|$ curl https://forge-ai.dev/api/markdown?path=docs/linux/processes
$cat docs/processes-&-services.md
updated Recently·24 min read·published
Processes & Services
Introduction
Every running program on Linux is a process with a unique PID. Services are long-running processes managed by an init system. Understanding how to inspect, control, and schedule processes is critical for operations and debugging.
Inspecting Processes
inspecting.sh
Bash
| 1 | # Snapshot of processes |
| 2 | ps aux |
| 3 | ps aux | grep nginx |
| 4 | |
| 5 | # Process tree |
| 6 | pstree |
| 7 | |
| 8 | # Real-time monitor |
| 9 | top |
| 10 | htop # interactive, requires installation |
| 11 | |
| 12 | # Find process by name |
| 13 | pgrep nginx |
| 14 | pidof nginx |
| 15 | |
| 16 | # Detailed info for a process |
| 17 | cat /proc/1234/status |
Signals
Signals are a form of inter-process communication. The kill command sends signals to processes.
| Signal | Value | Default Action |
|---|---|---|
| SIGHUP | 1 | Hang up / reload config |
| SIGINT | 2 | Interrupt (Ctrl+C) |
| SIGKILL | 9 | Force kill, cannot be caught |
| SIGTERM | 15 | Graceful termination |
| SIGSTOP | 19 | Pause (Ctrl+Z) |
| SIGCONT | 18 | Resume paused process |
signals.sh
Bash
| 1 | kill -TERM 1234 # graceful stop |
| 2 | kill -9 1234 # force kill |
| 3 | pkill node # kill all processes named node |
| 4 | killall firefox |
systemd Services
systemd.sh
Bash
| 1 | # View service status |
| 2 | sudo systemctl status nginx |
| 3 | |
| 4 | # Start, stop, restart, reload |
| 5 | sudo systemctl start nginx |
| 6 | sudo systemctl stop nginx |
| 7 | sudo systemctl restart nginx |
| 8 | sudo systemctl reload nginx # reload config without dropping connections |
| 9 | |
| 10 | # Enable / disable start on boot |
| 11 | sudo systemctl enable nginx |
| 12 | sudo systemctl disable nginx |
| 13 | |
| 14 | # List all active services |
| 15 | systemctl list-units --type=service --state=running |
| 16 | |
| 17 | # View logs |
| 18 | journalctl -u nginx |
| 19 | journalctl -u nginx -f # follow |
Background Jobs
jobs.sh
Bash
| 1 | # Run in background |
| 2 | long-running-task & |
| 3 | |
| 4 | # Send running process to background |
| 5 | Ctrl + Z |
| 6 | bg |
| 7 | |
| 8 | # Bring to foreground |
| 9 | fg %1 |
| 10 | |
| 11 | # List jobs |
| 12 | jobs -l |
| 13 | |
| 14 | # Run immune to hangups |
| 15 | nohup node server.js & |
| 16 | nohup node server.js > app.log 2>&1 & |
| 17 | |
| 18 | # Modern alternative: systemd user service or tmux/screen |
Scheduling with cron
cron.sh
Bash
| 1 | # Edit user crontab |
| 2 | crontab -e |
| 3 | |
| 4 | # List crontab |
| 5 | crontab -l |
| 6 | |
| 7 | # Example entries |
| 8 | # Run backup every day at 2 AM |
| 9 | 0 2 * * * /home/alice/backup.sh |
| 10 | |
| 11 | # Run health check every 5 minutes |
| 12 | */5 * * * * /usr/local/bin/health-check.sh |
| 13 | |
| 14 | # Run on Mondays at 9 AM |
| 15 | 0 9 * * 1 /opt/weekly-report.sh |
ℹ
info
Crontab format: minute hour day-of-month month day-of-week command. Use * for "every."