Process Management in Linux
Process management is crucial for monitoring and controlling system performance. Linux provides various commands to manage processes efficiently.
-
Run a command in the foreground:
ping 8.8.8.8
This command runs
pingand keeps it active in the current terminal. -
Run a command in the background:
ping 8.8.8.8 &The
&symbol runs the command in the background, allowing the terminal to be free for other tasks. -
Bringing a background job to the foreground:
fgThis command brings the last background job to the foreground.
-
Bringing a specific job to the foreground:
fg 2This brings job number 2 to the foreground.
- List all background jobs in the current terminal:
jobs
-
Show processes running in the current shell session:
ps
-
Display more details about running processes:
ps -L
-
List all processes with CPU and memory usage (BSD-style format):
ps -aux
-
List all processes using standard syntax:
ps -e
-
Display processes in a hierarchical tree format:
ps -axjf
-
Show processes owned by root:
ps -U root -u root u
-
Show processes owned by a specific user (e.g., armour):
ps -U armour -u armour
-
Display real-time system processes:
top
-
Better alternative to
top: Install and usehtopapt install htop # Debian/Ubuntu yum install htop # RHEL/CentOS htop
-
Show tree structure in
htop:htop -t
-
Display processes for a specific user (e.g., armour):
htop -t -u armour
-
Show details of a specific process by PID (e.g., 2780):
htop -t -p 2780
-
Terminate a process using its PID (e.g., 2526):
kill 2526 -
Forcefully kill a process (e.g., 7500):
kill -9 7500 -
Kill all instances of a process (e.g.,
sed):yum install psmisc killall seq
-
Kill all processes with names matching a pattern (e.g.,
firefox):killall -r firefox
-
Kill all processes owned by a specific user (e.g., armour):
killall -u armour
-
Kill all
pingprocesses usingpkill:pkill ping
-
Kill all processes owned by a user (e.g., armour):
pkill -u armour
-
Kill an exact process owned by a user (e.g.,
pingowned by armour):pkill -u armour -x ping