ps is the classic Unix/Linux command to list processes and their details. ps that ships with Linux is super-confusing to use because it supports three types of arguments: Unix options (
-u), BSD options (
x) and GNU options (
--pid). The format of the display will also be different based on which type of option you use! I wish the Linux ps did not have so much backward compatibility and was as simple as the OpenBSD ps.
- With no arguments, ps lists the processes associated with the current terminal:
This would have been useful many years ago, when Unix users put running programs to background and switched them back to foreground later. Today most Linux users just open multiple terminals to achieve the same, so this invocation is pretty useless.
Note that is lists the process ID (PID), the terminal of the process (TTY), time it has consumed (TIME) and the command invoked to start the process (CMD).
- To view details of a specific process using its PID, say 9999:
$ ps 9999
- To view all processes associated with a terminal:
$ ps a
- To view all processes on the system, try one of these:
$ ps ax $ ps -e
- To view the above processes, but with user (UID) of the processes:
$ ps aux $ ps -ef
Note that this command might be a bit slow since it needs to convert UIDs to usernames.
- To view the above processes, but with more excruciating details:
$ ps lax $ ps elf
- Any of the above options can be viewed with a simple ASCII tree linking parent and child processes. For example:
$ ps a --forest
- To view the environment variables associated with a process, provide its PID (say 9999):
$ ps eww 9999
- The columns that are displayed can be customized. For example:
$ ps -o user,pid,time,cmd