Processes and Resource Management: Monitoring What Runs on the Server
What Is a Process in Linux?
A process is a running instance of a program. When you type ls, the system creates a process, executes the command, and the process ends. Long-running applications like a Modbus gateway create processes that stay alive for months.
Every process has a PID (unique ID), PPID (parent process ID), an owner, a state (running, sleeping, stopped, zombie), and a priority.
On an industrial server, understanding processes is critical. A runaway data collector consuming 100% CPU can freeze your SCADA system. A zombie process holding a serial port open can block PLC communication. You need to find these problems and fix them quickly.
Listing Processes: ps and ps aux
ps # Your processes in the current terminal
ps aux # All processes with CPU and memory usage
ps aux | grep "[s]cada" # Find SCADA-related processes
ps -C gateway -o pid,user,%cpu,%mem # Specific columns for a named process
ps --forest # Parent-child tree view
Key columns in ps aux: %CPU (CPU usage), %MEM (memory usage), STAT (S=sleeping, R=running, Z=zombie), TIME (total CPU time).
The bracket trick [s]cada matches "scada" but not the grep command itself.
Live Monitoring: top and htop
top # Real-time process monitor
Key commands in top: P sort by CPU, M sort by memory, k kill a process, c show full command, q quit.
htop # Improved interactive monitor
sudo apt install htop # Install on Debian/Ubuntu
htop provides color-coded output, mouse support, and tree view (F5). You can also monitor specific processes:
top -p 1542 # Monitor only PID 1542
top -u scada # Only processes owned by scada user
Sending Signals: kill, killall, and pkill
| Signal | Number | Effect |
|---|---|---|
| SIGTERM | 15 | Graceful shutdown (default) |
| SIGKILL | 9 | Force kill immediately |
| SIGHUP | 1 | Reload configuration |
| SIGSTOP | 19 | Pause the process |
kill 1542 # SIGTERM (try this first)
kill -9 1542 # SIGKILL (only if SIGTERM fails)
kill -HUP 1542 # Reload config
killall gateway # Kill all processes named gateway
pkill -f "modbus_gateway" # Kill by command-line pattern
Always try SIGTERM first. SIGKILL cannot be caught and may leave data corrupted.
Background Processes: &, bg, fg, and nohup
./collect_sensors.sh & # Start in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
Press Ctrl+Z to suspend a foreground process, then bg to continue it in the background.
nohup ./long_task.sh > /var/log/task.log 2>&1 &
Without nohup, background processes die when you close your SSH session. With nohup, they survive. This is essential for overnight maintenance scripts on factory servers.
disown %1 # Detach a running job (also survives logout)
Practical Example: Monitoring and Stopping Hung Industrial App Processes
The SCADA dashboard is not updating. Let us diagnose:
# Find the process
ps aux | grep "[s]cada"
# scada 1542 98.3 1.5 524288 61440 ? R Apr14 342:45 /opt/scada/bin/gateway
# 98.3% CPU — it is hung in a loop. Check how long it has run:
ps -p 1542 -o pid,etime,%cpu,cmd
# Graceful shutdown first
kill 1542
sleep 3
# Still running? Force kill
ps -p 1542 && kill -9 1542
# Restart the service
sudo systemctl start scada-gateway
# Monitor the new process
top -p $(pgrep -f "scada.*gateway") -d 2
This workflow — identify, diagnose, gracefully stop, force stop if needed, restart, verify — is standard for hung processes on industrial servers.
Summary
In this lesson you learned how to manage processes on Linux:
- A process has a PID, owner, state, and resource usage.
ps auxlists all processes;grepfilters for specific ones.topandhtopprovide live CPU and memory monitoring.killsends signals: SIGTERM for graceful shutdown, SIGKILL as last resort.nohupand&run processes in the background that survive logout.- The diagnose-stop-restart workflow resolves hung process issues on industrial servers.
In the next lesson, you will learn Bash scripting to automate all the commands you have learned into scripts that run on their own.