Even a simple Linux system is usually doing a lot of things at once.

ps(1)

ps lists processes. If you run it with no options, it'll show you the processes running under your current login.

[email protected] ~ $ ps
  PID TTY          TIME CMD
30054 pts/2    00:00:00 bash
30116 pts/2    00:00:00 ps

The PID column lists a process ID. Every running program on the system will have one of these. If a process is stuck otherwise bothersome, you can stop it with kill [process ID].

If you want to see more detail about all of the things, try ps aux:

ps takes a gazillion different options in a confusing array of different formats, but memorizing one or two of them is usually good enough to give you a window into what's happening.

If you're looking for a specific program, you might try grepping the output of ps. Let's say I wanted to know about tmux sessions running on my Raspberry Pi. One approach might be ps aux | grep tmux:

Alternatively, you can use pgrep, which is specifically for finding process IDs:

[email protected] /proc/16514 $ pgrep -l tmux
16513 tmux
22350 tmux
30247 tmux

(The -l is for listing process names along with the PID.)

/proc

Under Linux, ps works by reading the files in /proc, which is a virtual filesystem full of info about running processes and suchlike things. If you know the id of a running process, you can inspect all sorts of info about it like so:

[email protected] ~ $ ps
  PID TTY          TIME CMD
16514 pts/1    00:00:01 bash
30268 pts/1    00:00:00 ps
[email protected] ~ $ cd /proc/16514
[email protected] /proc/16514 $ ls
autogroup        exe        mountstats     sched
auxv             fd         net            smaps
cgroup           fdinfo     ns             stack
clear_refs       io         oom_adj        stat
cmdline          limits     oom_score      statm
comm             maps       oom_score_adj  status
coredump_filter  mem        pagemap        syscall
cwd              mountinfo  personality    task
environ          mounts     root           wchan

top(1) and htop(1)

ps is useful for checking on the state of a running system or writing a shell pipeline, but often what you want is something more like an interactive monitor. Enter top:

top is old school, and it's probably available on just about every Unix system in use. Unfortunately, it's also kind of cryptic and difficult to read at a glance. My advice is to install htop instead - it's prettier, friendlier, and has a ton of features for sorting and filtering the process list.

sudo apt-get install htop

This guide was first published on Feb 24, 2015. It was last updated on Feb 24, 2015.

This page (Watch Processes) was last updated on Oct 18, 2021.

Text editor powered by tinymce.