| name | process-management |
| description | Linux process management and control |
| version | 1.0.0 |
| author | terminal-skills |
| tags | ["linux","process","kill","signal","jobs"] |
Process Management
Overview
Linux process viewing, signal handling, resource limiting and other management skills.
Process Viewing
ps Command
ps aux
ps -ef
ps -eo pid,ppid,cmd,%mem,%cpu
ps aux | grep nginx
ps -C nginx
ps auxf
pstree
pstree -p
top/htop
top
htop
Other Tools
ps aux --sort=-%cpu | head -10
ps aux --sort=-%mem | head -10
cat /proc/PID/status
cat /proc/PID/cmdline
ls -la /proc/PID/fd
Signal Handling
Common Signals
kill -l
kill Command
kill PID
kill -9 PID
kill -HUP PID
pkill nginx
pkill -9 -f "python script.py"
pkill -u username
killall nginx
killall -9 nginx
Background Tasks
Job Control
command &
nohup command &
nohup command > output.log 2>&1 &
jobs
fg %1
bg %1
Ctrl+Z
screen/tmux
screen -S session_name
screen -ls
screen -r session_name
Ctrl+A D
tmux new -s session_name
tmux ls
tmux attach -t session_name
Ctrl+B D
Resource Limits
ulimit
ulimit -a
ulimit -n 65535
ulimit -u 4096
ulimit -v unlimited
cgroups
cat /proc/PID/cgroup
systemctl set-property service.service CPUQuota=50%
systemctl set-property service.service MemoryLimit=512M
Common Scenarios
Scenario 1: Find and Kill Zombie Processes
ps aux | awk '$8=="Z" {print}'
ps -o ppid= -p ZOMBIE_PID
kill -9 PARENT_PID
Scenario 2: Find Process Using Port
lsof -i :80
ss -tlnp | grep :80
netstat -tlnp | grep :80
fuser -k 80/tcp
Scenario 3: Monitor Process Resources
top -p PID
watch -n 1 "ps -p PID -o %cpu,%mem,cmd"
lsof -p PID
Troubleshooting
| Problem | Solution |
|---|
| Process unresponsive | strace -p PID to view system calls |
| CPU 100% | top, perf top to analyze hotspots |
| Memory leak | pmap -x PID, /proc/PID/smaps |
| Zombie process | Find parent process, restart or kill parent |
| Process OOM killed | `dmesg |