Linux Command - ps

ps - display current processes. ps is short for Process Status.

ps displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top(1) instead.

ps has several options

  1. Unix Option - may be grouped and must be preceded by a dash
  2. BSD option - may be grouped and must NOT be preceded by a dash
  3. GNU long options, which are preceded by two dashes.

By default, ps selects all processes with the same effective user ID (euid=EUID) as the current user and associated with the same terminal as the invoker.

Syntax

1
ps [options]

Options

Option Description
-a show processes not associated with a terminal
-A Select all processes. Identical to -e.
-l long format
-f full-format listing
-u userlist select by effective user ID or name
a Lift the BSD-style “only yourself” restriction
u display user-oriented format
x Lift the BSD-style “must have a tty” restriction
l display BSD long format

Example

Display all process

1
ps -e

Sample output

1
2
3
4
5
6
PID TTY          TIME CMD
1 ? 00:01:05 systemd
2 ? 00:00:00 kthreadd
4 ? 00:00:00 kworker/0:0H
6 ? 00:00:00 mm_percpu_wq
7 ? 00:00:00 ksoftirqd/0

Display all process with full format

1
ps -ef

sample output

1
2
3
4
5
6
7
8
9
10
UID        PID  PPID  C STIME TTY          TIME CMD
xing 4470 3241 0 Dec25 ? 00:00:00 /usr/bin/zeitgeist-daemon
xing 4477 3241 0 Dec25 ? 00:00:00 /usr/lib/zeitgeist/zeitgeist/zeitgeist-fts
xing 4558 3405 0 Dec25 tty2 00:00:06 /usr/bin/gnome-software --gapplication-service
xing 4559 3405 0 Dec25 tty2 00:00:01 update-notifier
xing 4566 4559 0 Dec25 tty2 00:00:00 [livepatch-notif] <defunct>
root 4584 1 0 Dec25 ? 00:00:02 /usr/lib/fwupd/fwupd
root 4587 2 0 23:14 ? 00:00:00 [kworker/1:1]

...

Display process owned by root

1
ps -f -u root

sample output

1
2
3
4
5
6
7
UID        PID  PPID  C STIME TTY          TIME CMD
root 1 0 0 Dec25 ? 00:01:06 /sbin/init splash
root 2 0 0 Dec25 ? 00:00:00 [kthreadd]
root 4 2 0 Dec25 ? 00:00:00 [kworker/0:0H]
root 6 2 0 Dec25 ? 00:00:00 [mm_percpu_wq]
root 7 2 0 Dec25 ? 00:00:00 [ksoftirqd/0]
root 8 2 0 Dec25 ? 00:01:11 [rcu_sched]

Display all process(BSD syntax)

1
ps aux

sample output

1
2
3
4
5
6
7
8
9
10
11
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
systemd+ 6459 0.0 0.0 14280 1812 ? S Dec25 0:00 nginx: worker p
xing 6824 0.0 0.0 79960 5544 ? S Dec25 0:00 /usr/lib/x86_64
xing 7724 0.0 0.0 370520 7428 ? Sl Dec25 0:00 /usr/lib/gvfs/g
xing 7756 0.0 0.0 381288 7292 ? Sl Dec25 0:00 /usr/lib/gvfs/g
root 10242 0.0 0.0 10792 4840 ? Sl Dec25 0:02 containerd-shim
root 10262 0.0 0.0 18508 3472 pts/0 Ss+ Dec25 0:00 /bin/bash
root 11740 0.0 0.1 108092 8244 ? Ss 09:36 0:00 /usr/sbin/cupsd
root 11741 0.0 0.1 303672 10620 ? Ssl 09:36 0:00 /usr/sbin/cups-
xing 13042 0.0 1.8 1780472 146144 tty2 Sl+ 10:05 0:37 /usr/lib/chromi
xing 13499 0.1 1.5 1751396 124020 tty2 Sl+ 10:18 0:48 /usr/lib/chromi

search for a process’s PID

1
ps aux | grep node

sample output

1
2
ubuntu      9058  1.8  4.0 583200 39792 pts/4    Sl+  04:37   0:00 node index.js
ubuntu 9092 0.0 0.0 8160 736 pts/6 S+ 04:38 0:00 grep --color=auto node

ps aux | grep doesn’t show the header. To show process with header

1
ps aux | grep -v grep | grep -i -e VSZ -e node

You can also use pgrep process_name command to get the process id.

Reference