A process is a program that is running. Your shell is one, and so is every command you start from it. The ps command prints a snapshot of processes at the moment you run it. It does not update itself.
Plain ps
With no options, ps shows only your own processes that belong to the current terminal:
$ ps
PID TTY TIME CMD
2145 pts/0 00:00:00 bash
2310 pts/0 00:00:00 psPID is the process ID, a number the kernel uses to identify the process. TTY is the terminal it is attached to. TIME is the total CPU time it has used, not how long it has existed. CMD is the command name.
Seeing everything
The Linux ps accepts two styles of options. UNIX options take a dash. BSD options do not. These two commands are the common ways to list every process:
ps -ef
ps aux$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 167404 11520 ? Ss 09:00 0:01 /sbin/init
maria 2145 0.0 0.1 9212 5320 pts/0 Ss 09:12 0:00 -bashIn aux, a lifts the "only yours" limit, u picks the user-oriented columns, and x includes processes with no terminal. RSS is the physical memory in use, in kibibytes. VSZ is the virtual memory size, which is usually much larger.
ps -ef uses a different set of columns. It includes PPID (the parent's process ID) and C (processor use), but no memory percentage.
Choosing columns and sorting
Use -o to name the columns you want, and --sort to order them. A leading minus sorts from high to low.
$ ps -eo pid,user,%mem,comm --sort=-%mem | head -4
PID USER %MEM COMMAND
1893 maria 8.4 firefox
912 root 2.1 dockerd
640 root 0.9 NetworkManagerFinding one process
You can pipe into grep, but the grep command itself may appear in the results. pgrep avoids that:
$ pgrep -a sshd
778 sshd: /usr/sbin/sshd -DThe -a option prints the full command line next to each PID. The exact output differs between systems. To select by command name with ps itself, use ps -C sshd.
Try it
Run ps, then ps -ef, and compare how many lines each prints. Then list the five processes using the most CPU with ps aux --sort=-%cpu | head -6. You can practise safely in the processes and cron lab.
Check your understanding
The ps command: see what is running
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.