What is a Process?
Key Characteristics of a Process
- PID (Process ID) → A unique number assigned to every process. Example:
1234. - Parent/Child → Processes are created by other processes. The original one is
init(PID 1, usuallysystemd). - Resources → Each process uses CPU, memory, and I/O.
- State → A process can be running, sleeping (waiting), stopped, or terminated.
Examples of Processes
- When you open Firefox → a process is created (actually multiple).
- When you run
lsin the terminal → it becomes a short-lived process. - Background services (like networking, logging) → run as processes.
Process Management
In Linux, processes run constantly in the background or foreground. To keep the system stable and responsive, you need tools to view, monitor, and control these processes.
Viewing Processes
ps→ snapshot of active processes.a→ processes from all usersu→ show user infox→ include background/daemon processes
ps aux
Output:
USER PID %CPU %MEM COMMAND
amr 1342 0.2 1.1 bash
amr 1456 3.4 5.6 firefox
root 789 0.0 0.3 sshd
top→ live view of running processes.
top
The top command gives a live updating view of processes.
- Shows CPU %, memory usage, running time, and PID.
- Useful for finding processes consuming too many resources.
- Common keys inside
top: q→ quitk→ kill a process (enter PID)P→ sort by CPU usageM→ sort by memory usage
htop(if installed) → interactive process viewer.
htop
- A process = a running program.
- Identified by PID.
- Can be managed (started, stopped, killed, put in background/foreground).
- Processes are the building blocks of the Linux system — from desktop apps to hidden system services.
Terminate Processes
The kill command sends a signal to a process, usually to stop it.
- Kill by PID:
kill 1234
- Force kill (if normal kill doesn’t work):
kill -0 1234
- Kill by name (all processes with that name):
pkill firefox
Services & Daemons (systemctl, service)
In Linux, some processes run in the background without direct user interaction. These are known as daemons. They often start automatically at boot and keep running to provide essential services like networking, logging, and scheduling.
What is a Daemon?
- A daemon is a background process that waits for requests or performs tasks continuously.
- Examples:
sshd→ allows remote login via SSH.cron→ schedules tasks.cupsd→ manages printers.
- Daemons usually have names ending with
d.
What is a Service?
- A service is a managed daemon (or group of processes) that the operating system controls.
- Services are typically started/stopped/enabled through a service manager.
- On modern Linux, this is usually systemd, controlled via
systemctl.
Managing Services
With `systemctl` (systemd)
- Start a service:
sudo systemctl start ssh
- Stop a service:
sudo systemctl stop ssh
- Restart a service:
sudo systemctl restart ssh
- Check service status:
sudo systemctl status ssh
- Enable a service to start at boot:
sudo systemctl enable ssh
- Disable service at boot:
sudo systemctl disable ssh
Legacy Command: `service`
Older Linux systems (before systemd) use the service command. Some still support it for compatibility.
- Start service:
sudo service ssh start
- Stop service:
sudo service ssh stop
- Check status:
sudo service ssh status
- Daemon → a background process (e.g.,
sshd,cron). - Service → a daemon managed by the OS.
- systemctl → modern tool to control services.
- service → older command, sometimes still available.