MarzleyTech Learn

Home / Learn / Linux command line / Processes and installing software: ps, top, kill, jobs, apt, snap and keeping a system updated

Processes and installing software: ps, top, kill, jobs, apt, snap and keeping a system updated

Every running program on Linux is a process: your web server, the database, your SSH session, even the ls command while it runs. Administrators constantly check what's running, what's using the CPU and memory, and stop programs that misbehave. They also install, update and remove software using package managers, which download trusted software and handle dependencies automatically.

Processes and PIDs

Each process has a PID (process ID), an owner, and a parent process (PPID) that started it. The first process at boot is PID 1 (systemd on modern distros), the ancestor of everything else.

Terminal
ps                 # processes in this terminal
ps aux             # all processes on the system
ps aux | grep nginx    # find a specific program
pgrep -a python    # PIDs and command lines matching "python"
pstree             # processes as a tree

ps aux columns:

ColumnMeaning
USEROwner
PIDProcess ID
%CPU / %MEMShare of CPU and memory
VSZ / RSSVirtual / actual memory used
STATState: R running, S sleeping, Z zombie, T stopped
COMMANDThe program and its arguments

Live monitoring: top and htop

Terminal
top          # q to quit, P sort by CPU, M sort by memory, k to kill
sudo apt install htop
htop         # colourful, scrollable, easier (F9 kill, F6 sort)

The top lines show:

  • Load average (e.g. 0.45, 0.60, 0.70): average number of processes wanting CPU over 1, 5 and 15 minutes. Compare with the number of CPU cores (nproc): consistently above it means the system is overloaded.
  • Memory and swap: if swap usage keeps growing, the server needs more RAM or a process is leaking memory.

Other quick checks:

Terminal
free -h       # memory
uptime        # how long running + load average
nproc         # number of CPU cores

Stopping processes: signals

kill sends a signal to a process:

SignalNumberMeaning
SIGTERM15"Please stop" (default): the program can clean up
SIGKILL9Force stop immediately (can't be ignored; no clean-up)
SIGHUP1Hang up; many servers reload their configuration on it
SIGINT2Interrupt (what Ctrl+C sends)
Terminal
kill 4321            # polite stop (SIGTERM)
kill -9 4321         # force (use only if SIGTERM doesn't work)
pkill -f "python app.py"   # by matching the command line
killall firefox      # all processes with that name

Always try plain kill first; -9 can leave temporary files or corrupt data.

Foreground and background jobs

Terminal
python3 long_task.py        # runs in the foreground; the terminal waits
# press Ctrl+Z to pause it
bg                          # continue it in the background
jobs                        # list background jobs
fg %1                       # bring job 1 back to the foreground
python3 long_task.py &      # start directly in the background

Background jobs stop when you log out. To keep something running after you disconnect from a server:

Terminal
nohup python3 long_task.py > task.log 2>&1 &

Better options for long-running work: tmux or screen (terminal sessions you can detach from and reattach later), or a proper systemd service (see the services lesson).

Process priority

Terminal
nice -n 10 ./backup.sh      # start with lower priority (higher nice = nicer to others)
sudo renice -n 5 -p 4321    # change priority of a running process

Package managers

A package manager installs software from trusted repositories, verifies it, and installs any dependencies (other packages it needs).

Distro familyToolPackage format
Ubuntu, Debian, Mint, Kaliapt.deb
Fedora, RHEL, Rocky, AlmaLinuxdnf.rpm
Archpacman
Alpineapk
Cross-distrosnap, flatpaksandboxed apps

Using apt (Ubuntu/Debian)

Terminal
sudo apt update                 # refresh the list of available packages (do this first)
sudo apt upgrade                # install updates for everything
sudo apt install nginx          # install
sudo apt install git curl unzip # several at once
sudo apt remove nginx           # remove (keeps config files)
sudo apt purge nginx            # remove including config
sudo apt autoremove             # remove dependencies no longer needed
apt search image editor         # search
apt show nginx                  # details: version, size, description
apt list --installed | grep php # what's installed

apt update only refreshes the catalogue; apt upgrade actually updates software. A common beginner mistake is to run install without update on a fresh server and get "package not found".

dnf (Fedora/RHEL) in brief

Terminal
sudo dnf check-update
sudo dnf upgrade
sudo dnf install nginx
sudo dnf remove nginx
dnf search nginx

Snap and flatpak

Terminal
sudo snap install code --classic   # VS Code
snap list
sudo snap refresh

Snaps bundle their dependencies and update automatically; they're convenient for desktop apps.

Other ways to install software (and the risks)

MethodExampleCaution
A .deb filesudo apt install ./package.debOnly from the official vendor site
Vendor repositoryAdding Docker's or Node's official repoFollow the vendor's official instructions
PPA (Ubuntu)sudo add-apt-repository ppa:...Third-party; trust matters
Language package managerspip, npm, composerUse virtual environments/project folders
Piping a downloaded script into bashInstall scriptsRead the script first; you're running it as you (or root)

Keeping servers patched

Unpatched software is one of the main ways servers get hacked.

Terminal
sudo apt update && sudo apt upgrade -y
sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades   # enable automatic security updates
cat /var/run/reboot-required 2>/dev/null                    # does a kernel update need a reboot?

Plan reboots for quiet hours (e.g. late night in Kenya for local-audience sites), and test major upgrades on a staging server first.

Think about it: A server feels very slow. uptime shows a load average of 7.8 on a 2-core machine, and top shows a php process at 190% CPU. What steps would you take?Show answer

Note its PID and investigate (which site/script, recent changes, logs). If it's stuck or runaway, stop it with kill PID, then kill -9 only if needed. Fix the cause (a bad script, a loop, a bot attack, missing cache) and consider limits or more CPU. Load 7.8 on 2 cores means heavy overload.

Summary

  • Every running program is a process with a PID and parent; PID 1 is systemd.
  • ps aux, pgrep, top/htop, free -h and uptime show what's running and resource use; compare load with nproc.
  • kill sends signals: TERM (15) to stop politely, KILL (9) to force.
  • Ctrl+Z, bg, fg, & and nohup/tmux manage jobs.
  • apt update then apt install/upgrade/remove; dnf on Fedora/RHEL; snap for apps; keep servers patched with unattended-upgrades.

Check yourself

  1. What is a running program's unique number called? (abbreviation)

    Show answer

    PID

  2. Which signal number forcefully kills a process?

    Show answer

    9

  3. Which apt command refreshes the list of available packages? (three words)

    Show answer

    sudo apt update

  4. Which command lists all processes on the system? (two words)

    Show answer

    ps aux

  5. Which key combination pauses a foreground process?

    Show answer

    Ctrl+Z

  6. Which package manager does Fedora use?

    Show answer

    dnf

Lesson 7 of 12 in Linux command line · Written by · Course notes