Home/Learn/Linux/Processes, Jobs & Signals

Processes, Jobs & Signals

Beginner
Processes

A process is a running program with its own PID, memory, and file descriptors. Linux tools like ps, top, htop, kill, and job control let you monitor, manage, and signal any process.

Overview

When you run a command, the shell forks a child process. Every process has a unique PID (Process ID), a PPID (parent PID), an owner, resource usage (CPU, memory), and a state (running, sleeping, zombie). Signals are software interrupts sent to processes — SIGTERM asks nicely to stop, SIGKILL forces immediate termination, SIGHUP reloads config. Job control (fg, bg, &, Ctrl-Z) lets you manage multiple processes in the same terminal session. Understanding this is essential for debugging hanging processes, managing long-running servers, and writing init scripts.

Process Inspection

ps, top, and htop show the process table. Each provides a different view of what is running on the system.

bash — process inspection commands
# ps — process snapshot
ps aux
# USER  PID  %CPU %MEM    VSZ   RSS TTY  STAT  START   TIME COMMAND
# root    1   0.0  0.1 168940  9056 ?    Ss    10:00   0:01 /sbin/init
# akshay 1234 0.5  2.3 1234568 94012 pts/0 Sl  10:05   0:12 node server.js

# Columns explained:
# STAT: S=sleeping, R=running, Z=zombie, D=uninterruptible sleep, T=stopped
# VSZ: virtual memory (allocated, may not be in RAM)
# RSS: resident set size (actual RAM in use)

# Find a specific process
ps aux | grep nginx
pgrep nginx                 # just the PIDs
pgrep -a nginx              # PIDs + command names

# Process tree (who spawned whom)
pstree -p                   # full tree with PIDs
pstree -p 1234              # tree rooted at PID 1234

# top — live updating process list
top
# Press: q=quit, k=kill, r=renice, 1=per-CPU, M=sort by memory, P=sort by CPU
# htop — improved version with color, mouse support, F-key shortcuts
htop

Signals

Signals are asynchronous notifications sent to a process. The process's signal handler determines what happens. Some signals (SIGKILL, SIGSTOP) cannot be caught or ignored.

bash — signals and kill
# Common signals
# Signal   Number  Default action  Description
# SIGHUP       1   Terminate       Hangup / reload config (nginx uses this)
# SIGINT       2   Terminate       Ctrl-C from keyboard
# SIGQUIT      3   Core dump       Ctrl-\ (quit with core dump)
# SIGTERM     15   Terminate       Graceful stop (default for kill)
# SIGKILL      9   Kill (forced)   Cannot be caught/ignored/blocked
# SIGUSR1     10   Terminate       User-defined (nginx: reopen log files)
# SIGSTOP     19   Stop            Cannot be caught; Ctrl-Z equivalent
# SIGCONT     18   Continue        Resume a stopped process

# kill — send a signal to a process
kill 1234             # sends SIGTERM (15) — ask process to stop gracefully
kill -9 1234          # sends SIGKILL — force-kill immediately
kill -HUP $(pgrep nginx)  # reload nginx config without restart
kill -s SIGTERM 1234  # verbose form

# killall and pkill
killall nginx         # kill all processes named "nginx"
pkill -f "node server" # kill by matching command string

# Sequence: try graceful first, then force
kill 1234             # SIGTERM — wait a few seconds
kill -9 1234          # SIGKILL only if SIGTERM didn't work

# Send Ctrl-C programmatically
kill -INT 1234

Job Control & Background Processes

Job control lets you run multiple commands in one terminal. nohup and disown keep processes running after you log out.

bash — job control and background processes
# Run in background with &
./long-script.sh &           # starts in background, returns to prompt
# [1] 18423                  ← job number and PID

# Job management
jobs                         # list background jobs
fg                           # bring last background job to foreground
fg %1                        # bring job 1 to foreground
bg %1                        # resume stopped job 1 in background

# Ctrl-Z → suspend current foreground job (sends SIGSTOP)
# then:
bg                           # resume it in background

# nohup — survive terminal close (SIGHUP)
nohup python3 server.py &           # output goes to nohup.out
nohup python3 server.py > app.log 2>&1 &

# disown — detach already-running background job from terminal
./server.sh &
disown %1                    # job now owned by init, survives logout

# screen / tmux — persistent terminal sessions
tmux new -s mysession        # new named session
tmux attach -t mysession     # reattach from another terminal
# Ctrl-b d  → detach (session stays running)

# See all processes you own
ps aux | grep $USER

Key Points to Remember

  • 1Every process has a PID, PPID, owner, state, and resource usage.
  • 2SIGTERM (15) is the polite stop signal; SIGKILL (9) is the forceful, uncatchable one.
  • 3Always try SIGTERM first — give the process a chance to clean up; use SIGKILL only as a last resort.
  • 4Ctrl-Z sends SIGSTOP (suspends); bg resumes in background; fg brings to foreground.
  • 5nohup + & or disown keeps processes running after logout.
  • 6SIGHUP is conventionally used to tell daemons (nginx, sshd) to reload their configuration.

Interview Questions

Sign in to ask Aria
1

What is the difference between kill -9 and kill -15?

2

What is a zombie process?

Ask Aria about Processes, Jobs & Signals

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…