Processes

Show processes commands
Command Description
ps report a snapshot of current processes
top display tasks
jobs list active jobs
bg place a job in the background
fg place a job in the foreground
kill send a signal to a process
killall kill processes by name
shutdown shutdown or reboot the system
pstree list process arranged in a tree-like pattern (child-parent)
vmstat display a snapshot of system resource usage
xload display a graph showing system load over time
tload as xload but, draws the graph in the terminal

When a system starts up, the kernel initiates a few of its own activities as processes and launches a program called init. init, in turn, runs a series of shell scripts (located in /etc) called init scripts, which start all the system services.

ps

ps – without options doesn’t show much

Columns

Column name Description
PID each process is assigned a number called a process ID
TTY (short for “Teletype”) refers to the controlling terminal for the process
STAT short for “state” and reveals the current status of the process*
USER User ID, owner of the process
%CPU CPU usage in percent
%MEM memory usage in percent
VSZ virtual memory size
RSS (Resident Set Size) amount of physical memory (RAM) the process is using in kilobytes
START time when the process started

*Process states

Abbreviation Meaning Description
R running process is running or ready to run
S sleeping process is not running, it is waiting for an event, such as a keystroke or network packet
D uninterruptible sleep waiting for I/O such as a disk drive
T stopped process has been instructed to stop.
Z defunct or “zombie” process a child process that was terminated, but has not been cleaned up by its parent.
< high priority process grant more importance to a process, giving it more time on the CPU
N low priority process process with low priority, will only get processor time after other processes with higher priority have been serviced

ps options

Option Description
x show all processes regardless of what terminal they are controlled by
aux get these additional columns (marked * in the table Columns)
PID each process is assigned a number called a process ID
top

– ps provides only a snapshot of the machine’s state at the moment the ps command is executed, to see a more dynamic view use top (continuously updating, by default, every 3 seconds)
– similar to Task Manager in Windows
– use q to quit top

bg, fg, &, jobs

– Ctrl-c – interrupts a program (we politely asked the program to terminate)
– Ctrl-z – stop a foreground process
– & – placed after the command will put process in the background (diplay PID and return shell prompt)
– fg (fg followed by a percent sign and the job number) – return a process to the foreground
– bg – return a process to the background
– jobs – list the jobs that are have been launched from our terminal

A process in the background is immune from keyboard input, including any attempt interrupt it with a Ctrl-c.

Signals

The kill command doesn’t exactly “kill” programs, rather it sends them signals. Signals are one of several ways that the operating system communicates with programs. We have already seen signals in action with the use of Ctrl-c and Ctrl-z.

– kill followed by %jobspec or PID

Sending Signals To Processes With kill

The kill command is used to send signals to programs.
Syntax:
kill [-signal] PID...

If no signal is specified on the command line, then the TERM (Terminate) signal is sent by
default.

Number Name Meaning
1 HUP Hangup. From old days when computers were attached to remote computers with phone lines and modems. It’s basically a terminate signal.
2 INT Interrupt. Same as Ctrl-c, it will terminate a program.
9 KILL Never actually sent to the target program. Rather, the kernel immediately terminates the process. When a process is terminated in this manner, it is given no opportunity to “clean up” after itself or save its work. It should only be used as a last resort.
15 TERM Terminate. This is the default signal sent by the kill command. If a program is still “alive” enough to receive signals, it will terminate.
18 CONT Continue. Restore a process after a STOP signal.
19 STOP Stop. Pause without terminating. Like the KILL signal, it is not sent to the target process, and thus it cannot be ignored.

Example of use:
kill -1 13546
kill -INT 13601
kill -SIGINT 13608

Use kill -l to view full list of signals.

Send signals to multiple processes with killall command.
Syntax:
killall [-u user] [-signal] name...