Linux process management is a core skill for system operations and development. Each process has a unique process ID (PID), parent process ID (PPID), and running state.
Common process management commands:
- ps: view current process status, common options include ps aux (show all processes), ps -ef (full format display), ps -l (long format display)
- top/htop: real-time monitoring of system processes and resource usage, htop provides a more friendly interactive interface
- kill: terminate processes, e.g., kill PID (send SIGTERM signal), kill -9 PID (force terminate, send SIGKILL signal)
- killall: terminate processes by name, e.g., killall nginx
- pkill: terminate processes by pattern matching, e.g., pkill -f "python script.py"
- pgrep: find process IDs, e.g., pgrep nginx
- nohup: let commands run continuously in the background, e.g., nohup command &
- &: run commands in the background, e.g., command &
- jobs: view background tasks of the current shell
- bg/fg: switch tasks to background/foreground
Process states include:
- R (Running): running or waiting in the run queue
- S (Sleeping): interruptible sleep
- D (Uninterruptible Sleep): uninterruptible sleep
- T (Stopped): stopped
- Z (Zombie): zombie process
Zombie processes are processes that have completed but whose parent process has not yet read their exit status. The parent process needs to call wait() or waitpid() to reclaim them. Orphan processes are processes whose parent has terminated but are still running, and they will be adopted by the init process (PID 1).
Inter-process communication (IPC) methods include pipes, message queues, shared memory, semaphores, sockets, etc.