ps reports information about active processes. It provides information about which user owns the process, when the process started, the command path used to execute the process, the PID, the terminal it is attached to (TTY, for TeleTYpe), the memory used by the process, the CPU time used by the process, and so on. Consider the following example:
$ ps PID TTY TIME CMD 1220 pts/0 00:00:00 bash 1242 pts/0 00:00:00 ps
Be default, ps will display the processes initiated from the current terminal (TTY). The first column shows the PID, the second column refers to the terminal (TTY), the third column indicates how much time has elapsed since the process started, and finally we have CMD (the command).
The ps command report can be modified with command-line parameters.
The -f (full) option displays more columns of information:
$ ps -f UID PID PPID C STIME TTY TIME CMD slynux 1220 1219 0 18:18 pts/0 00:00:00 -bash slynux 1587 1220 0 18:59 pts/0 00:00:00 ps -f
The -e (every) and -ax (all) options provide a report on every process that is running on the system.
The commands ps -e, ps -ef, ps -ax, and ps -axf generate reports on all processes and provide more information than ps:
$ ps -e | head -5 PID TTY TIME CMD 1 ? 00:00:00 init 2 ? 00:00:00 kthreadd 3 ? 00:00:00 migration/0 4 ? 00:00:00 ksoftirqd/0
The -e option generates a long report. This example filters the output with head to display the first five entries.
The -o PARAMETER1, PARAMETER2 option specifies the data to be displayed.
The -o option can be combined with the -e (every) option (-eo) to list every process running in the system. However, when you use filters similar to the ones that restrict ps to the specified users along with -o, -e is not used. The -e option overrules the filter and displays all the processes.
In this example, comm stands for COMMAND and pcpu represents the percentage of CPU usage:
$ ps -eo comm,pcpu | head -5 COMMAND %CPU init 0.0 kthreadd 0.0 migration/0 0.0 ksoftirqd/0 0.0