appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Processes, services and system health

Lesson 5 of 510 minBeginner

See what is running, stop what misbehaves, manage services with systemctl and read their logs.

Processes

A process is a running program. Each has a number, its PID.

ps aux                # list all processes
ps aux | grep nginx   # find one by name
top                   # live view (q to quit); htop is a friendlier alternative
kill 1234             # ask process 1234 to stop politely (SIGTERM)
kill -9 1234          # force it to stop (SIGKILL), last resort

Carefulkill -9 gives the program no chance to clean up. Try plain kill first.

Services with systemctl

Servers run long-lived programs called services, managed by systemd:

systemctl status nginx        # is it running? last log lines
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx  # stop and start
sudo systemctl reload nginx   # reread config without dropping connections, if supported
sudo systemctl enable nginx   # start automatically at boot
systemctl list-units --type=service --state=failed

Logs with journalctl

journalctl -u nginx           # all logs for the service
journalctl -u nginx -n 50     # last 50 lines
journalctl -u nginx -f        # follow live
journalctl -p err -b          # errors since the last boot

Disk, memory and uptime

df -h        # free disk space per file system, human readable
du -sh *     # size of each item in the current folder
free -h      # memory use
uptime       # how long it has been running and the load average

Running things in the background

  • command & runs it in the background.
  • Ctrl+C stops the current command, Ctrl+Z suspends it.
  • For long jobs over SSH, use tmux or screen, so they survive a dropped connection.

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

Hintsystemctl has a status subcommand.
Hintjournalctl, with -u for the unit and -n for the number of lines.
Hintdf means "disk free".
4. Which should you try first to stop a misbehaving process?

Key terms