Commands for displaying, monitoring, and controlling 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 terminalps -ef
- Display all processes in full formatps aux
- Display all processes in user-oriented formatps -u root
- Display processes owned by root userps --sort=-%cpu
- Sort by CPU usage (highest first)ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
- Display top processes by memory usageps -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 IDps -U root -u root u
- Display processes owned by root in detailed formatps aux --forest
- Display processes in tree structure (shows parent-child relationships)
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-timetop -d 5
- Update every 5 secondstop -n 10
- Update 10 times then exittop -u username
- Display only processes for specific usertop -b -n 1 > top_output.txt
- Run once in batch mode and save output to filetop -b -n 1 | grep "firefox"
- Extract information for specific process (firefox in this case)top -c
- Show full command pathtop -o %MEM
- Sort by memory usagetop -i
- Hide idle processes
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 htophtop -u username
- Display only processes for specific userhtop -p 1234,5678
- Display only specified process IDshtop -s PERCENT_MEM
- Sort by memory usagehtop -d 10
- Update every 10 secondshtop -t
- Start in tree view modehtop --readonly
- Start in read-only mode (prevents changes via operations)htop -C
- Start in monochrome mode (useful in some environments)
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 1234kill -9 1234
- Forcefully terminate process ID 1234kill -HUP 1234
- Send restart signal to process ID 1234kill -l
- List all available signalskill -0 1234
- Check if process exists (sends no signal, returns exit code 0 if process exists)kill $(pgrep firefox)
- Terminate process by namekill -SIGSTOP 1234
- Pause process (can be resumed with SIGCONT)kill -SIGCONT 1234
- Resume paused process
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 processeskillall -9 httpd
- Forcefully terminate all httpd processeskillall -u username firefox
- Terminate firefox processes for specific userkillall -i chrome
- Ask for confirmation before killing each processkillall -w firefox
- Wait for processes to diekillall -r "fire.*"
- Kill processes matching regular expression (firefox, firefox-esr, etc.)killall -o 15m bash
- Kill bash processes running for more than 15 minuteskillall -y 10m -o 1h bash
- Kill bash processes running for more than 1 hour but not accessed in the last 10 minutes
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 -5sudo renice 10 -u username
- Lower priority of all processes owned by specific usernice
- Display current shell's nice valuenice -n 19 tar -czf backup.tar.gz /home/user
- Run backup process with lowest prioritysudo renice -n 5 -g 1000
- Change priority of all processes in group ID 1000ps -o pid,ni,cmd | grep firefox
- Check current nice value of specific processsudo renice -n 0 -p $(pgrep -d ' ' firefox)
- Change priority of multiple process IDs at once
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 logoutnohup wget https://example.com/large-file.iso &
- Download file in background, continue after terminal closesnohup ./script.sh > custom_output.log 2>&1 &
- Redirect stdout and stderr to specified filenohup ./script.sh > /dev/null 2>&1 &
- Discard output (when logs aren't needed)nohup nice -n 19 ./backup.sh &
- Run in background with low priorityecho 'nohup ./script.sh &' | at midnight
- Schedule nohup command to run at specified timenohup 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.
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 backgroundjobs
- List background jobsfg %1
- Bring job ID 1 to foregroundbg %2
- Resume job ID 2 in backgroundjobs -l
- List background jobs with process IDsjobs -p
- Display only process IDs of background jobsfg %%
- Bring most recently suspended job to foregroundbg $(jobs -p | tail -1)
- Resume last job in backgroundkill %1
- Terminate job ID 1disown %1
- Detach job ID 1 from shell's job control (continues running after logout)