We can easily view processes, using ps
(process status). This only displays the processes that run from the current terminal, so are limited.
$ ps
PID TTY TIME CMD
2696 pts/0 0:00:00 bash
2745 pts/0 0:00:00 ps
At the most basic level, there are only four columns.
As we'll see soon, the ps
command comes with a variety of options. Depending on where these options originated, you may or may not need dashes preceding the option letter.
The -f
option prints full format listing, meaning it includes additional parameters. The -e
or -A
options displays all processes (including daemon).
$ ps -ef
UID PID PPID C STIME TTY TIME CMD root 1 0 3 11:14 ? 00:00:00 /sbin/init root 2 0 0 11:14 ? 00:00:00 [kthreadd] root 3 2 0 11:14 ? 00:00:00 [ksoftirqd/0] root 4 2 0 11:14 ? 00:00:00 [kworker/0:0] root 5 2 0 11:14 ? 00:00:00 [kworker/0:0H] root 6 2 1 11:14 ? 00:00:00 [kworker/u2:0] root 7 2 0 11:14 ? 00:00:00 [rcu_sched] root 8 2 0 11:14 ? 00:00:00 [rcuos/0] root 9 2 0 11:14 ? 00:00:00 [rcu_bh]
You'll notice that some processes have a TTY
of ?
. This means that they have no controlling terminals. Many of these are daemon processes.
Here are some more parameters listed, adding onto the list above.
To view all processes belonging to a user, use the -u
option, followed by the username. If you want to view more than one username, separate the names with a comma.
$ ps -u JohnDoePC
# List all processes started by JohnDoePC
By attaching an aux
option (no hyphen), we can see even more details. The a
shows processes for all users, the u
displays the process's owner, and the x
shows processors not attached to a terminal.
Additionally, the w
option shows the full command name, not just what fits on one line.
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.4 0.4 33772 2012 ? Ss 22:53 0:01 /sbin/init
root 2 0.0 0.0 0 0 ? S 22:53 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 22:53 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S 22:53 0:00 [kworker/0:0]
root 5 0.0 0.0 0 0 ? S< 22:53 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? S 22:53 0:00 [kworker/u2:0]
root 7 0.2 0.0 0 0 ? S 22:53 0:00 [rcu_sched]
root 8 0.0 0.0 0 0 ? S 22:53 0:00 [rcuos/0]
root 9 0.0 0.0 0 0 ? S 22:53 0:00 [rcu_bh]
Here are some more variables that we see.
Here are some variables that go along with the STAT
column.
To access the current shell's PID, use the shortcut $$
. This evaluates to the current shell's PID.
$ ps u $$
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
JohnDoe 13030 0.0 0.0 27112 4092 pts/8 Ss 00:39 0:00 bash
If you want to see where each process spawned from, we can use the -H
, -f
or --forest
option. You'll see that each child process branches out with tabs, signifying its origin
$ ps -AH
...
1 ? 00:00:01 init
299 ? 00:00:00 upstart-udev-br
304 ? 00:00:00 systemd-udevd
517 ? 00:00:00 upstart-socket-
774 ? 00:00:00 upstart-file-br
783 ? 00:00:00 rsyslogd
792 ? 00:00:03 dbus-daemon
805 ? 00:00:00 ModemManager
816 ? 00:00:00 systemd-logind
818 ? 00:00:00 bluetoothd
850 ? 00:00:01 avahi-daemon
852 ? 00:00:00 avahi-daemon
...
One drawback with using ps
is that it's static - we cannot see the changes while they occur. For a more dynamic view of currently running processes, we can use the top
command.
In this completely revised second edition of the perennial best seller How Linux Works, author Brian Ward makes the concepts behind Linux internals accessible to anyone curious about the inner workings of the operating system. Inside, you'll find the kind of knowledge that normally comes from years of experience doing things the hard way.
$ Check priceThis foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.
$ Check priceAd