Master Linux Process Management: From Basics to Advanced Commands
This article explains what programs and processes are, details process states and types, shows how to view and control processes with commands like ps, top, pgrep, pstree, free, iostat, and iotop, and covers manual start, termination, and scheduling of tasks on Linux.
What is a program
A set of instructions that a computer can recognize and execute, guiding it to perform specific tasks or solve problems. Programs typically consist of code, data, and resource files, involving syntax, algorithms, and data structures, and are compiled into binary files.
What is a process
A process is an independent execution instance of a program that operates on a data set. It is the basic unit of resource allocation and scheduling in an operating system, forming the foundation of OS structure.
Relationship between program and process
Process states
Basic process states
Created: the process requests a blank PCB (process control block) and fills control information; if resources are insufficient, it cannot be scheduled.
Ready: the process has all required resources and can run as soon as the CPU is allocated.
Running: the process moves to execution after being scheduled from the ready state.
Blocked: the process temporarily cannot run due to I/O requests or resource waits; it returns to ready when the condition is satisfied.
Terminated: the process ends due to completion, error, or system termination and cannot run further.
Additional states
Running (running)
Ready (ready)
Sleep: interruptible and uninterruptible
Stopped: paused in memory, not scheduled unless manually started
Zombie: terminated process whose parent hasn't waited; can be cleared by killing the parent.
How to eliminate zombie state
Creating a zombie process
Use top or ps to view zombie (Z) PID
Send a kill signal to wake the zombie's parent process and recycle the zombie
# kill -18 6904Alternatively, kill the zombie's parent process, which is not recommended.
Process types
Daemon: a background service started during system boot, unrelated to any terminal.
Foreground: a process associated with a terminal, started from the terminal.
Process priority
Static priority: 100‑139
Dynamic priority: -20 to 19
Process management commands
ps
View static process statistics; information is stored in the /proc directory. Without options, only limited information is shown.
# ps
PID TTY TIME CMD
6950 pts/2 00:00:00 bash
7441 pts/2 00:00:00 psCommon usage: ps aux Options for ps aux:
a – show all processes
u – display in user‑oriented format
x – show processes without a controlling terminal
k / --sort – sort by attribute (prefix - for descending)
ps output fields
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
top
Real‑time view of process statistics.
# top
top - 17:01:45 up 4:08, 4 users, load average: 0.00, 0.01, 0.05
Tasks: 209 total, 1 running, 208 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.1 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1867048 total, 76652 free, 796612 used, 993784 buff/cache
KiB Swap: 2097148 total, 2097004 free, 144 used. 810116 avail Mem
...Field meanings:
PID – process ID
USER – owning user
PR – priority (lower number = higher priority)
NI – nice value (lower number = higher priority)
VIRT – virtual memory size (KB)
RES – resident (physical) memory size (KB)
SHR – shared memory size (KB)
S – process state
%CPU – CPU usage percentage
%MEM – memory usage percentage
TIME+ – total CPU time used
COMMAND – command name
Commands in top
q – quit
s – change refresh interval
k – kill a specified process
w – write configuration to file
pgrep
Find processes by name or user.
# pgrep -u asdjkl
9828
9834
9841
...pstree
Display processes in a tree structure.
# pstree -a
systemd --switched-root --system --deserialize 21
├─ModemManager
│ └─[{ModemManager}]
├─NetworkManager --no-daemon
│ └─[{NetworkManager}]
...free
Show detailed memory usage.
# free
total used free shared buff/cache available
Mem: 1867048 1247944 119912 13656 499192 358276
Swap: 2097148 6572 2090576iostat
Provide I/O performance statistics.
Total DISK READ: 0.00 B/s Total DISK WRITE: 0.00 B/s
Actual DISK READ: 0.00 B/s Actual DISK WRITE: 0.00 B/s
...iotop
Monitor network traffic.
Process management
Manual start
Use command & to run a command in the background.
Running jobs: Ctrl+Z sends a job to the background but stops it.
Unstarted jobs: command & List background tasks: jobs Bring a background task to the foreground: fg Continue a stopped task: bg Parallel execution: separate commands with &.
Terminate process
kill
The kill command sends a signal to a process; the signal type is user‑specified.
# trap -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 ... 64) SIGRTMAXScheduled tasks
One‑time tasks
# at 13:50
at> mkdir kk
at> ^D
job 1 at Thu Apr 18 13:50:00 2024Periodic tasks
Use crontab to schedule recurring jobs.
-u user – set crontab for a specific user
-e – edit crontab
-l – list crontab
-r – remove crontab
-i – confirm before removal
* * * * *
# minute hour day month weekSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
