
Terminal - Commands using ps - 184 results
ps axo rss,comm,pid | awk '{ proc_list[$2] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc],proc); }}' | sort -n | tail -n 10
This is sample output - yours may be different.
ps axo rss,comm,pid | awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc "," 1],proc); }}' | sort -n | tail -n 10
This is sample output - yours may be different.
2472 NetworkManager
3624 getty
3888 hald
3948 nm-system-setti
3968 gdm
4012 bash
6384 sshd
14348 apache2
20560 console-kit-dae
22104 mysqld
This command loops over all of the processes in a system and creates an associative array in awk with the process name as the key and the sum of the RSS as the value. The associative array has the effect of summing a parent process and all of it's children. It then prints the top ten processes sorted by size.
psgrep() { if [ ! -z $1 ] ; then echo "Grepping for processes matching $1..." ps aux | grep -i $1 | grep -v grep else echo "!! Need name to grep for" fi }
This is sample output - yours may be different.
eva:~ even$ psgrep sky
Grepping for processes matching sky...
kessia 253 0,0 1,1 482148 23132 ?? S Qui04 1:13.61 /Applications/Skype.app/Contents/MacOS/Skype -psn_0_73746
Grep for a named process.
ps axo rss,comm | awk '{sum+=$1; print $1/1024, "MB - ", $2} END {print "\nTotal RAM Used: ", sum/1024, "MB\n"}'
This is sample output - yours may be different.
This command basically adds up all of the individual instances processes and gives you a grand total for used memory in that instance alone.
ps aux | sed -n '/USER/!s/\([^ ]\) .*/\1/p' | sort -u
This is sample output - yours may be different.
avahi
dbus
hal
mark
mysql
This is different that `who` in that who only cares about logged-in users running shells, this command will show all daemon users and what not; also users logged in remotely via SSH but are running SFTP/SCP only and not a shell.
This is sample output - yours may be different.
By setting the UNIX95 variable in HP-UX the XPG4 mode is activated, you get new options for ps and other commands, for me the best way to use this is to create an alias named ptree in root profile: alias ptree='UNIX95=1 ps -eH'
for i in $(ps -ef | awk '{print $2}') ; { swp=$( awk '/Swap/{sum+=$2} END {print sum}' /proc/$i/smaps ); if [[ -n $swp && 0 != $swp ]] ; then echo -n "\n $swp $i "; cat /proc/$i/cmdline ; fi; } | sort -nr
This is sample output - yours may be different.
4428 9187 python/usr/share/system-config-printer/applet.py
2012 9163 gnome-panel
1516 9127 /usr/lib/gnome-settings-daemon/gnome-settings-daemon
1408 18899 /usr/lib/gvfs/gvfsd-smb--spawner:1.9/org/gtk/gvfs/exec_spaw/4
1040 1681 gnome-terminal
Col 1 is swapped sum in kb
Col 2 is pid of process
Col 3 is command that was issued
while (ps -ef | grep [r]unning_program_name); do sleep 10; done; command_to_execute
This is sample output - yours may be different.
The '[r]' is to avoid grep from grepping itself. (interchange 'r' by the appropriate letter)
Here is an example that I use a lot (as root or halt will not work):
while (ps -ef | grep [w]get); do sleep 10; done; sleep 60; halt
I add the 'sleep 60' command just in case something went wrong; so that I have time to cancel.
Very useful if you are going to bed while downloading something and do not want your computer running all night.
port=8888;pid=$(lsof -Pan -i tcp -i udp | grep ":$port"|tr -s " " | cut -d" " -f2); ps -Afe|grep "$pid"|grep --invert-match grep | sed "s/^\([^ ]*[ ]*\)\{7\}\(.*\)$/\2/g"
This is sample output - yours may be different.
java -Dcom.sun.management.jmxremote -Xmx1024m -XX:MaxPermSize=300m -server -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8885 -jar /oc4j/j2ee/home/oc4j.jar
A way not so simple but functional for print the command for the process that's listening a specific port.
I got the pid from lsof because I think it's more portable but can be used netstat
netstat -tlnp
ps -ef | grep user | awk '{print $2}' | while read pid; do echo $pid ; pfiles $pid| grep portnum; done
This is sample output - yours may be different.
My old Solaris server does not have lsof, so I have to use pfiles.
for x in `ptree | awk '{print $1}'`; do pfiles $x | grep ${PORT} > /dev/null 2>&1; if [ x"$?" == "x0" ]; then ps -ef | grep $x | grep -v grep; fi; done 2> /dev/null
This is sample output - yours may be different.
root@shell02:~# for x in `ptree | awk '{print $1}'`; do pfiles $x | grep -w ${PORT} > /dev/null 2>&1; if [ x"$?" == "x0" ]; then ps -ef | grep $x | grep -v grep; fi; done 2> /dev/null
root 5386 5331 0 Oct 06 ? 1:29 /lib/svc/bin/svc.configd
root 6211 6209 0 Oct 06 ? 0:02 /usr/lib/autofs/automountd
root 17437 6425 0 09:02:56 ? 0:00 /usr/lib/ssh/sshd
root 6425 5331 0 Nov 10 ? 18:54 /usr/lib/ssh/sshd
root 17437 6425 0 09:02:56 ? 0:00 /usr/lib/ssh/sshd
bob 17438 17437 0 09:02:56 ? 0:00 /usr/lib/ssh/sshd
bob 17438 17437 0 09:02:56 ? 0:00 /usr/lib/ssh/sshd
bob 17441 17438 0 09:02:57 pts/1 0:00 -sh
daemon 12227 5331 0 Dec 03 ? 0:00 /usr/lib/nfs/statd
daemon 12232 5331 0 Dec 03 ? 0:00 /usr/lib/nfs/lockd
root@shell02:~#
Can use lsof, but since it's not part of the base OS, it's not always available.
stop () { ps -ec | grep $@ | kill -SIGSTOP `awk '{print $1}'`; }
This is sample output - yours may be different.
Add that and "cont () { ps -ec | grep $@ | kill -SIGCONT `awk '{print $1}'`; }" (without the quotes) to you bash profile and then use it to pause and resume processes safely
ps -ylC httpd --sort:rss | awk '{ SUM += $8 } END { print SUM/1024 }'
This is sample output - yours may be different.
This command will show you amount of memory used by apache
ps aux | grep [h]ttpd | cat -n
This is sample output - yours may be different.
If you're on a system that doesn't have nl, you can use cat -n.
ps aux | grep [a]pache2 | nl
This is sample output - yours may be different.
1 root 2459 0.0 0.4 24068 7408 ? Ss Dec09 0:00 /usr/sbin/apache2 -k start
2 www-data 5191 0.0 0.5 26312 10068 ? S Dec11 4:28 /usr/sbin/apache2 -k start
3 www-data 5909 0.0 0.5 26312 10064 ? S Dec11 4:02 /usr/sbin/apache2 -k start
4 www-data 5991 0.0 0.5 26312 10252 ? S Dec11 4:05 /usr/sbin/apache2 -k start
...
98 www-data 12931 0.0 0.4 25144 8308 ? S 13:28 0:00 /usr/sbin/apache2 -k start
99 www-data 12932 0.0 0.4 25144 8312 ? S 13:28 0:00 /usr/sbin/apache2 -k start
100 www-data 12933 0.0 0.4 25144 8316 ? S 13:28 0:00 /usr/sbin/apache2 -k start
Write each FILE to standard output, with line numbers added. With no FILE, or when FILE is -, read standard input.
ps ax| awk '/[h]ttpd/{print $1}'| xargs kill -9
This is sample output - yours may be different.
ps aux| grep -v grep| grep httpd| awk {'print $2'}| xargs kill -9
This is sample output - yours may be different.
ps -o thcount -p <process id>
This is sample output - yours may be different.
psu(){ command ps -Hcl -F S f -u ${1:-$USER}; }
This is sample output - yours may be different.
$ psu askapache
F S PID PPID CLS PRI ADDR SZ WCHAN RSS PSR TTY CMD
5 S 4111 4099 TS 19 - 1790 poll_s 1556 0 ? sshd: askapache@pts/0
0 S 4121 4111 TS 19 - 743 wait 1792 3 pts/0 \_ -bash
0 R 22083 4121 TS 19 - 641 - 824 0 pts/0 \_ ps -Hcl -F S f -u askapache
$ psu root
4 S 1 0 TS 19 - 486 poll_s 372 0 ? init [2]
1 S 7007 1 TS 19 - 690 poll_s 1104 1 ? /sbin/syslog-ng -p /var/run/syslog-ng.pid
5 S 7015 1 TS 19 - 1076 poll_s 852 0 ? /usr/sbin/sshd
4 S 4099 7015 TS 19 - 1720 unix_s 2160 0 ? \_ sshd: askapache [priv]
4 S 22256 7015 TS 19 - 1076 sk_wai 1848 1 ? \_ sshd: [accepted]
ps -ec -o command,rss | grep Stainless | awk -F ' ' '{ x = x + $2 } END { print x/(1024) " MB."}'
This is sample output - yours may be different.
Adds up the total memory used by all Stainless processes: 1 Stainless, 1 StainlessManager and 1 StainlessClient per tab open.
ps -eo pcpu,user,pid,cmd | sort -r | head -5
This is sample output - yours may be different.
ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f\t%.2f\n",num[user], user, cpu[user], mem[user]) }'
This is sample output - yours may be different.
The original version gives an error, here is the correct output
This is sample output - yours may be different.
root 21 0.0 0.0 0 0 ? S< Oct10 0:11 [ata/0]
68 1417 0.0 0.2 6772 2900 ? Ss Oct10 0:14 hald
root 1586 0.0 0.1 17184 1836 ? Ssl Oct10 0:14 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid
root 1554 0.0 0.0 3516 564 ? S Oct10 0:19 hald-addon-storage: polling /dev/sr0 (every 2 sec)
ali 2013 0.0 0.9 247540 10068 ? S Oct10 0:24 kwin -session 10dad4d46f000125200430400000021020032_1255123367_509351
dbus 1377 0.0 0.1 13492 1484 ? Ssl Oct10 0:25 dbus-daemon --system
root 47 0.0 0.0 0 0 ? S< Oct10 0:29 [scsi_eh_1]
ali 2047 0.0 1.5 123976 15816 ? Rl Oct10 0:44 yakuake -session 10dad4d46f000125165081500000020800011_1255123367_401521 -name Qt-subapplication
ali 2323 0.1 0.2 1610188 2528 ? Ss Oct10 0:52 C:\windows\system32\explorer.exe /desktop
ali 2021 0.1 2.2 287952 23152 ? Sl Oct10 1:37 /usr/bin/plasma-desktop
ali 2299 0.2 0.0 5404 992 ? Ss Oct10 2:24 /usr/bin/wineserver
root 6341 0.5 7.0 122288 72160 pts/3 S+ 00:33 0:33 /usr/bin/python /usr/bin/yum groupinstall GNOME Desktop Environment
ali 2296 0.6 0.7 1694604 8076 ? Sl Oct10 5:03 C:\Program Files\www.cproxy.com\cproxy.exe
ali 2191 0.8 0.2 100880 2160 ? Ssl Oct10 7:07 /usr/bin/pulseaudio --start --log-target=syslog
ali 6164 1.2 3.2 165432 33084 ? Sl 00:30 1:20 /usr/bin/kopete -caption Kopete
ali 4854 2.6 2.2 147408 22468 ? Sl Oct10 6:07 /usr/lib/nspluginwrapper/npviewer.bin --plugin /usr/lib/mozilla/plugins/libflashplayer.so --connection /org/wrapper/NSPlugins/libflashplayer.so/4759-1
ali 4546 2.9 5.9 228028 61048 ? Sl Oct10 7:24 /usr/lib/songbird-1.2.0/./songbird-bin
root 1840 5.9 2.7 55864 28172 tty1 Ss+ Oct10 49:50 /usr/bin/X -br -nolisten tcp :0 vt1 -auth /var/run/xauth/A:0-lhNFjm
ali 4759 16.6 18.4 652080 187640 ? Sl Oct10 38:56 /usr/lib/firefox-3.5.3/firefox
ali 7231 2.0 0.0 4764 988 pts/0 R+ 02:16 0:00 ps aux --sort=%mem,%cpu
you can also pipe it to "tail" command to show 10 most memory using processes.
This is sample output - yours may be different.
ps -C program_name || { program_name & }
This is sample output - yours may be different.