$ Linux Commands

Process Management — Viewing and controlling running processes

htop Process Management

Interactive process viewer (enhanced top)

htop
htop

Install with: sudo apt install htop. Use F9 to kill, F6 to sort, F5 for tree view.

journalctl Process Management

Query the systemd journal (logs)

journalctl [OPTIONS] [MATCHES]
journalctl -u nginx
journalctl -u myapp -n 50
journalctl -u myapp -f
journalctl --since "1 hour ago"
-u UNIT show logs for a service
-n N show last N lines
-f follow (live output)
-r newest first
--since filter by date/time
kill Process Management

Send a signal to a process

kill [OPTIONS] PID
kill 1234
kill -9 1234
kill -SIGTERM 1234
-9 / -SIGKILL force kill immediately
-15 / -SIGTERM graceful shutdown (default)

Get the PID from ps aux or pgrep. Use -9 only if graceful shutdown fails.

nohup Process Management

Run a command immune to hangups

nohup COMMAND [ARGS] &
nohup python script.py &
nohup ./server.sh > output.log 2>&1 &

Output goes to nohup.out by default. Use & to run in the background.

pgrep Process Management

Find processes by name

pgrep [OPTIONS] PATTERN
pgrep nginx
pgrep -l python
-l show process name alongside PID
-u USER filter by user
pkill Process Management

Kill processes by name

pkill [OPTIONS] PATTERN
pkill nginx
pkill -9 python
-9 force kill
-u USER only kill that user's processes
ps Process Management

Report a snapshot of current processes

ps [OPTIONS]
ps aux
ps aux | grep nginx
ps -ef
aux all processes with user and CPU/mem
-ef full listing, all users

Pipe to grep to find a specific process: ps aux | grep python

screen Process Management

Terminal multiplexer — keep sessions alive after disconnect

screen [OPTIONS] [COMMAND]
screen -S mysession
screen -r mysession
screen -ls
-S NAME name the session
-r NAME reattach to a session
-ls list sessions

Inside screen: Ctrl+A then D to detach. Ctrl+A then K to kill.

systemctl Process Management

Control the systemd system and service manager

systemctl COMMAND [UNIT]
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl status nginx
sudo systemctl enable nginx
sudo systemctl disable nginx
sudo systemctl daemon-reload
start start a service
stop stop a service
restart restart a service
status show service status
enable start on boot
disable do not start on boot
daemon-reload reload unit files
top Process Management

Display Linux processes in real time

top
top
top -u alice
-u USER show only that user's processes

Press q to quit, k to kill a process, M to sort by memory, P to sort by CPU.