ps
From Initq
In most Unix-like operating systems, ps is a program that displays the currently running processes. A related Unix utility named top provides a real-time view of the running processes.
Contents |
Examples
An example of the ps command is:
tux ~ # ps PID TTY TIME CMD 7431 pts/0 00:00:00 su 7434 pts/0 00:00:00 bash 18585 pts/0 00:00:00 ps
The ps command can also be used in conjunction with the grep command to find information about one process, such as its process id. An example of this is:
tux ~ # ps -A | grep firefox-bin 11778 ? 02:40:08 firefox-bin 11779 ? 00:00:00 firefox-bin
Options
ps has many options. On operating systems that support the UNIX and POSIX standards, ps is commonly run with the options -ef, where "-e" selects every process and "-f" chooses the "full" output format. Another common option on these systems is -l, which specifies the "long" output format.
Most systems derived from BSD fail to accept the POSIX and UNIX standard options because of historical conflicts (for example, the "e" or "-e" option will cause environment variabless to be displayed). On such systems, ps is commonly used with the non-standard options aux, where "a" lists all processes on a terminal, including those of other users, "x" lists all processes without controlling terminals and "u" adds the controlling user for each process. Note that, for maximum compatibility when using this syntax, there is no "-" in front of the "aux". Also you can add 'www' after aux, like "ps auxwww" for complete information about the process including all params.
Flags
- u display user-oriented format
- -u user
- --forest three structure
- w wide
- a all
[alibaba@ohnonono junk]$ ps u U alibaba USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND alibaba 7596 0.0 0.0 8996 1612 ? S 12:15 0:00 sshd: alibaba@pts/1 alibaba 7597 0.0 0.0 4504 1436 pts/1 Ss 12:15 0:00 -bash alibaba 9152 0.0 0.0 4228 936 pts/1 R+ 16:36 0:00 ps u U alibaba alibaba 29294 0.0 0.0 4504 1404 pts/3 S+ May24 0:00 -bash alibaba 29921 0.0 0.0 4500 1400 pts/4 S+ May24 0:00 -bash
If you want to look at just the command column then
- ps -xo comm
if you want to look at command and memory then
- ps -xo comm,pmem | sort +1n | uniq | tac
See a particular users processes
You can use the -fu flag followed by the username.
-bash-3.00$ ps -fu jbadmin UID PID PPID C STIME TTY TIME CMD jbadmin 29780 22043 0 09:32:33 pts/2 0:00 ps -fu jbadmin jbadmin 22041 22038 0 Oct 27 ? 0:00 /usr/lib/ssh/sshd jbadmin 29777 29764 0 09:17:38 pts/2 2:07 /opt/apptricity/jdk-1_5_0_09-solaris-i586/jdk1.5.0 jbadmin 29764 1 0 09:17:37 pts/2 0:00 /bin/sh /opt/apptricity/jboss-4.2.3/bin/runapptricity40.sh jbadmin 22043 22041 0 Oct 27 pts/2 0:00 -bash
