Linux Process Management | ps top kill jobs Commands
ps command, top command, htop, kill, pkill, background processes, jobs, fg, bg
Linux Process Management
Every running program on a Linux system is a process. Each process has a unique process ID (PID), an owner, resource usage statistics, and a state. Understanding how to view, manage, and control processes is a critical Linux system administration skill covered in Linux basics courses and used daily in production environments.
Viewing Processes with ps
The ps command displays a snapshot of current processes. The most common usage is ps aux, which shows all processes for all users with detailed information including CPU and memory usage.
ps aux
ps aux | grep nginx
ps -ef
ps -u aliceThe output columns include USER (process owner), PID (process ID), %CPU, %MEM, STAT (process state), and COMMAND (the command that started the process).
Interactive Process Monitoring with top and htop
The top command shows a real-time, updating view of system processes and resource usage. It displays CPU usage, memory usage, load average, and a list of the most resource-intensive processes. Press Q to exit. Press M to sort by memory, P to sort by CPU usage.
top
htophtop is an improved interactive version of top with color, mouse support, and easier process management. Install it with sudo apt install htop.
Killing Processes
The kill command sends a signal to a process by PID. The most common signals are SIGTERM (15, graceful shutdown) and SIGKILL (9, immediate termination). The pkill command kills processes by name instead of PID.
kill 1234
kill -9 1234
pkill nginx
pkill -f "python3 server.py"Background and Foreground Jobs
Append an ampersand (&) to run a command in the background. The jobs command lists background jobs. Use fg to bring a job to the foreground and bg to resume a stopped job in the background.
sleep 100 &
jobs
fg %1
bg %2
Ctrl+Z # pause a foreground processCtrl+C sends SIGINT to terminate a foreground process. Ctrl+Z pauses it and moves it to background in stopped state.
