Skip to content

Process Management


Terminal window
ps aux # all processes, full detail
ps aux | grep nginx # find a specific process
ps -ef # full-format listing (alt style)
ps -p 1234 # info for a specific PID
ColumnMeaning
USEROwner of the process
PIDProcess ID
%CPUCPU usage
%MEMMemory usage
STATState (R=running, S=sleeping, Z=zombie)
COMMANDCommand that started the process

Terminal window
top # built-in live monitor
htop # better UI (may need install)

top key bindings:

KeyAction
kKill a process (enter PID)
MSort by memory
PSort by CPU
qQuit

Terminal window
kill 1234 # graceful stop (SIGTERM)
kill -9 1234 # force kill (SIGKILL)
kill -HUP 1234 # reload config (SIGHUP)
killall nginx # kill all processes named nginx
killall -9 node # force kill all node processes

Common signals:

SignalNumberMeaning
SIGTERM15Graceful shutdown (default)
SIGKILL9Force kill, cannot be caught
SIGHUP1Reload config / restart
SIGINT2Interrupt (same as Ctrl+C)

Terminal window
command & # run in background
Ctrl+Z # suspend current process
bg # resume suspended job in background
fg # bring background job to foreground
fg %2 # bring job #2 to foreground
jobs # list all background/suspended jobs

Runs a command that keeps running after you log out.

Terminal window
nohup ./script.sh & # run in background, immune to hangup
nohup ./script.sh > out.log 2>&1 & # capture stdout + stderr

Output goes to nohup.out by default unless redirected.


Terminal window
command > file.txt # stdout to file (overwrite)
command >> file.txt # stdout to file (append)
command 2> err.txt # stderr to file
command > out.txt 2>&1 # stdout + stderr to same file
command 2>/dev/null # discard stderr
command1 | command2 # pipe stdout of cmd1 into cmd2

Terminal window
pgrep nginx # print PIDs of processes named nginx
pgrep -l nginx # print PID + name
pkill nginx # kill all processes named nginx
pkill -9 node # force kill by name

Terminal window
lsof -i :8080 # what process is using port 8080
lsof -i TCP # all TCP connections
lsof -p 1234 # files opened by PID 1234
lsof -u username # files opened by user

Terminal window
systemctl start nginx # start a service
systemctl stop nginx # stop a service
systemctl restart nginx # restart
systemctl reload nginx # reload config without restart
systemctl status nginx # check status
systemctl enable nginx # start on boot
systemctl disable nginx # don't start on boot
systemctl list-units # list all active units

  • Always try kill (SIGTERM) before kill -9 — give the process a chance to clean up.
  • pgrep -l is faster than ps aux | grep for finding a PID.
  • Use nohup + & for long-running jobs on remote servers.
  • lsof -i :PORT is the fastest way to find what’s occupying a port.

← Linux