# Processes, Signals and Resources

> Understand how Linux runs programs, how to inspect and stop them, and how the kernel shares CPU and memory between them. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/devops/processes-signals
Last updated: 2026-11-28

Understand how Linux runs programs, how to inspect and stop them, and how the kernel shares CPU and memory between them.

Beginner · about 6 hours · difficulty 2/5

Learn first: [Linux Command Line and Packages](https://www.internhack.in/roadmaps/tracks/devops/linux-basics)

Every running program is a **process** with a PID, a parent, an owner, open file descriptors and a slice of CPU and memory. When a service misbehaves in production, you will be inspecting processes.

### Key concepts

- **fork and exec**: new processes are cloned from a parent, then replaced with a new program. PID 1 is the init system (or your app, inside a container).
- **States**: running, sleeping, stopped, and **zombie** (finished but not reaped by its parent).
- **Signals**: `SIGTERM` asks a process to stop gracefully, `SIGKILL` forces it, `SIGHUP` often means "reload config", `SIGINT` is Ctrl+C. Apps should handle SIGTERM to shut down cleanly; Kubernetes and Docker send it before killing.
- **Foreground and background jobs**: `&`, `jobs`, `fg`, `bg`, `nohup`.
- **Priorities and limits**: `nice`, `renice`, `ulimit` (open files is a classic production limit).

### Tools

`ps aux`, `pstree`, `top`/`htop`, `kill`, `pgrep`/`pkill`, `lsof` (who has this file or port open), and the `/proc` filesystem, which exposes every process as a directory.

### Pitfalls

Reaching for `kill -9` first (no cleanup, possible corruption), and forgetting that a container whose PID 1 ignores SIGTERM will take the full grace period to stop.

**Good enough to move on:** you can find which process is using a port, explain what happens when you send SIGTERM versus SIGKILL, and read a process's limits in /proc.

## Key concepts

- **PIDs, parents and fork/exec**
- **Signals: TERM, KILL, HUP, INT**
- **ps, top, htop, pgrep**
- **lsof and file descriptors**
- **Jobs, nohup and background work**
- **nice and ulimit**
- **/proc filesystem**
- **cgroups and namespaces**: The kernel features containers are built on

## Mini project

Write a tiny program that traps SIGTERM and logs a graceful shutdown message, run it in the background, then use pgrep, lsof and kill to find and stop it while watching the log.

## Check yourself

Why might a containerised app take 30 seconds to stop, and how would you fix it?

## Free resources

- [Linux Journey: Processes](https://linuxjourney.com/) (linuxjourney.com)
- [signal(7) man page](https://man7.org/linux/man-pages/man7/signal.7.html) (man7.org)

Previous: [Linux Command Line and Packages](https://www.internhack.in/roadmaps/tracks/devops/linux-basics) · Next: [Filesystems, Disks and Storage](https://www.internhack.in/roadmaps/tracks/devops/filesystems-storage)

## More in Living on Linux

- [Linux Command Line and Packages](https://www.internhack.in/roadmaps/tracks/devops/linux-basics)
- [Processes, Signals and Resources](https://www.internhack.in/roadmaps/tracks/devops/processes-signals)
- [Filesystems, Disks and Storage](https://www.internhack.in/roadmaps/tracks/devops/filesystems-storage)
- [Users, Groups and Permissions](https://www.internhack.in/roadmaps/tracks/devops/users-permissions)
- [Services with systemd](https://www.internhack.in/roadmaps/tracks/devops/systemd-services)
- [Performance and Troubleshooting](https://www.internhack.in/roadmaps/tracks/devops/linux-performance)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [DevOps Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/devops)
