Processes, services and system health
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 resortCarefulkill -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=failedLogs 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 bootDisk, 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 averageRunning 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
tmuxorscreen, 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.