Master Linux Process Management: From Programs to Commands and Scheduling
This article explains what programs and processes are, their relationship, various process states and types, priority levels, and provides practical guidance on using essential Linux commands such as ps, top, pgrep, pstree, free, iostat, iotop, as well as job control, kill signals, and scheduling tools like at and crontab.
What Is a Program
A program is a set of instructions that a computer can recognize and execute to perform a specific task or solve a problem, typically composed of code, data, and resource files and compiled into a binary.
What Is a Process
A process is an independent execution instance of a program that operates on a specific data set; it is the basic unit for resource allocation and scheduling in an operating system.
Relationship Between Program and Process
The following diagram illustrates how a program becomes a process when it is loaded and executed.
Process States
The diagram below shows the lifecycle of a process.
Basic states:
Created: The process requests a blank PCB (process control block) and allocates resources; if allocation fails, it cannot be scheduled.
Ready: All required resources are allocated and the process can run as soon as it gets CPU time.
Running: The process is executing after being scheduled from the ready state.
Blocked: The process is temporarily unable to run due to I/O requests or other events; it returns to ready when the event is resolved.
Terminated: The process ends normally, crashes, or is killed by the system.
Additional states:
Running (running)
Ready (ready)
Sleep (interruptible / uninterruptible)
Stopped (stopped, can be resumed manually)
Zombie (zombie, remains until the parent process reaps it)
How to Remove a Zombie Process
Example of creating a zombie process and then using top or ps to locate it (state Z) and its PID.
Terminate a zombie by sending a signal to its parent process: kill -18 6904 Alternatively, killing the zombie’s parent process works but is not recommended.
Process Types
Daemon: A background service started during system boot, unrelated to any terminal.
Foreground: Processes started from a terminal and associated with it.
Process Priority
Static priority range: 100‑139.
Dynamic priority range: -20 to 19.
Process Management Commands
ps
Displays static process statistics. Process information is stored in the /proc directory. Without options, ps shows limited data; the common usage is ps aux.
Key fields:
USER : Process owner.
PID : Process ID.
%CPU : CPU usage percentage.
%MEM : Memory usage percentage.
VSZ : Virtual memory size (KB).
RSS : Resident set size, physical memory used (KB).
STAT : Process state.
START : Start time.
TIME+ : Cumulative CPU time.
COMMAND : Command name.
top
Shows real‑time process statistics.
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 stField explanations (us, sy, ni, id, wa, hi, si, st) are provided in the article.
pgrep
Searches for processes matching criteria.
Common options: -u: Specify user. -l: Show process name. -a: Show full command line.
# pgrep -u asdjkl
9828
9834
...pstree
Displays processes in a tree structure.
Useful options: -a: Show full command line. -p: Show PIDs. -u: Show user IDs. -H pid: Highlight a specific PID and its ancestors.
systemd─┬─ModemManager───{ModemManager}
└─NetworkManager───{NetworkManager}free
Shows memory usage details.
Mem: 1867048 total 1247944 used 119912 free 13656 shared 499192 buff/cache 358276 availableiostat
Provides detailed 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/siotop
Monitors real‑time I/O usage, including network traffic.
Manual Process Control
Run a command in the background with command &. Use Ctrl+Z to suspend a running job and then bg to resume it in the background. List background jobs with jobs, bring a job to the foreground with fg, and run multiple commands in parallel by separating them with &.
Ending Processes
kill
The kill command sends a signal to a process; the signal type is user‑specified. Use trap -l to list available signals.
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
...Scheduled Tasks
One‑time tasks (at)
# at 13:50
at> mkdir kk
at> ^D
job 1 at Thu Apr 18 13:50:00 2024Recurring tasks (crontab)
Common options: -u user: Operate on a specific user’s crontab. -e: Edit the crontab. -l: List the crontab. -r: Remove the crontab. -i: Prompt before removal.
Crontab time fields: minute hour day month weekday.
Signed-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.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.
