Linux Process Management Commands Guide

Process Management Commands

Commands for displaying, monitoring, and controlling processes.

ps - Display Processes

Displays running processes.

Option Description
-e, -A Display all processes
-f Display in full format (with additional information like parent process ID)
-l Display in long format
-u [user] Display processes for specified user
-p [pid] Display process with specified process ID
--sort=[column] Sort by specified column (e.g., --sort=-%cpu)
-o [format] Customize output format

Examples:

ps - Display processes for current terminal
ps -ef - Display all processes in full format
ps aux - Display all processes in user-oriented format
ps -u root - Display processes owned by root user
ps --sort=-%cpu - Sort by CPU usage (highest first)
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head - Display top processes by memory usage
ps -C nginx - Display processes with specific name (nginx in this case)
ps -p 1234 -o pid,ppid,cmd,lstart - Display details and start time for specific process ID
ps -U root -u root u - Display processes owned by root in detailed format
ps aux --forest - Display processes in tree structure (shows parent-child relationships)

top - Monitor Processes in Real-time

Monitors system processes in real-time.

Option/Key Description
-d [seconds] Specify update interval in seconds
-n [iterations] Update specified number of times then exit
-p [pid] Monitor only specified process IDs
-u [user] Display only processes of specified user
k Kill a process (press k while running)
r Renice a process (change priority, press r while running)
f Select fields to display (press f while running)
q Quit top (press q while running)

Examples:

top - Monitor processes in real-time
top -d 5 - Update every 5 seconds
top -n 10 - Update 10 times then exit
top -u username - Display only processes for specific user
top -b -n 1 > top_output.txt - Run once in batch mode and save output to file
top -b -n 1 | grep "firefox" - Extract information for specific process (firefox in this case)
top -c - Show full command path
top -o %MEM - Sort by memory usage
top -i - Hide idle processes

htop - Enhanced Process Viewer

An enhanced version of top with a more user-friendly interface.

Key Description
F1-F10 Shortcuts to various functions
Space Mark/unmark a process
F9 Kill marked processes
F6 Select sort column
F5 Toggle tree view
F2 Show setup menu

Examples:

htop - Launch htop
htop -u username - Display only processes for specific user
htop -p 1234,5678 - Display only specified process IDs
htop -s PERCENT_MEM - Sort by memory usage
htop -d 10 - Update every 10 seconds
htop -t - Start in tree view mode
htop --readonly - Start in read-only mode (prevents changes via operations)
htop -C - Start in monochrome mode (useful in some environments)

kill - Terminate Processes

Sends signals to processes with specified process IDs.

Option/Signal Description
-l List available signals
-1, -HUP HUP (hangup) signal - often used to restart processes or reload configuration
-2, -INT INT (interrupt) signal - equivalent to Ctrl+C
-9, -KILL KILL signal - forcefully terminate process (use when process is unresponsive)
-15, -TERM TERM signal - default signal, requests normal termination

Examples:

kill 1234 - Send termination signal (TERM) to process ID 1234
kill -9 1234 - Forcefully terminate process ID 1234
kill -HUP 1234 - Send restart signal to process ID 1234
kill -l - List all available signals
kill -0 1234 - Check if process exists (sends no signal, returns exit code 0 if process exists)
kill $(pgrep firefox) - Terminate process by name
kill -SIGSTOP 1234 - Pause process (can be resumed with SIGCONT)
kill -SIGCONT 1234 - Resume paused process

killall - Terminate Processes by Name

Sends signals to all processes matching the specified name.

Option Description
-i Ask for confirmation before killing each process
-I Case-insensitive process name matching
-u [user] Kill only processes owned by specified user
-s [signal] Specify signal to send
-v Report if the signal was successfully sent

Examples:

killall firefox - Terminate all firefox processes
killall -9 httpd - Forcefully terminate all httpd processes
killall -u username firefox - Terminate firefox processes for specific user
killall -i chrome - Ask for confirmation before killing each process
killall -w firefox - Wait for processes to die
killall -r "fire.*" - Kill processes matching regular expression (firefox, firefox-esr, etc.)
killall -o 15m bash - Kill bash processes running for more than 15 minutes
killall -y 10m -o 1h bash - Kill bash processes running for more than 1 hour but not accessed in the last 10 minutes

nice/renice - Set/Change Process Priority

Set or change the priority (nice value) of processes. Nice values range from -20 (highest priority) to 19 (lowest priority), with 0 as default.

Command/Option Description
nice -n [value] [command] Run command with specified priority
renice [value] -p [pid] Change priority of running process
renice [value] -u [user] Change priority of all processes owned by specified user

Examples:

nice -n 10 ./script.sh - Run script with low priority (10)
sudo nice -n -10 ./important_task - Run task with high priority (-10)
sudo renice -5 -p 1234 - Change priority of process ID 1234 to -5
sudo renice 10 -u username - Lower priority of all processes owned by specific user
nice - Display current shell's nice value
nice -n 19 tar -czf backup.tar.gz /home/user - Run backup process with lowest priority
sudo renice -n 5 -g 1000 - Change priority of all processes in group ID 1000
ps -o pid,ni,cmd | grep firefox - Check current nice value of specific process
sudo renice -n 0 -p $(pgrep -d ' ' firefox) - Change priority of multiple process IDs at once

nohup - Run Process Immune to Hangups

Runs a command that continues running after you log out or close the terminal.

Syntax Description
nohup [command] & Run command in background, continue running after terminal closes

Examples:

nohup ./long_running_script.sh & - Run script in background, continue after logout
nohup wget https://example.com/large-file.iso & - Download file in background, continue after terminal closes
nohup ./script.sh > custom_output.log 2>&1 & - Redirect stdout and stderr to specified file
nohup ./script.sh > /dev/null 2>&1 & - Discard output (when logs aren't needed)
nohup nice -n 19 ./backup.sh & - Run in background with low priority
echo 'nohup ./script.sh &' | at midnight - Schedule nohup command to run at specified time
nohup bash -c "for i in {1..10}; do ./task.sh; sleep 60; done" & - Run multiple commands with nohup

Output is normally redirected to a file called "nohup.out" in the current directory.

bg/fg - Background/Foreground Job Control

Control jobs running in background or foreground.

Command Description
command & Run command in background
Ctrl+Z Suspend running process
bg Resume suspended job in background
bg %[job_id] Resume specified job in background
fg Resume most recently suspended job in foreground
fg %[job_id] Resume specified job in foreground
jobs List background jobs

Examples:

./long_script.sh & - Run script in background
jobs - List background jobs
fg %1 - Bring job ID 1 to foreground
bg %2 - Resume job ID 2 in background
jobs -l - List background jobs with process IDs
jobs -p - Display only process IDs of background jobs
fg %% - Bring most recently suspended job to foreground
bg $(jobs -p | tail -1) - Resume last job in background
kill %1 - Terminate job ID 1
disown %1 - Detach job ID 1 from shell's job control (continues running after logout)