A container is a normal Linux process with some extra rules. So to understand containers you need a few Linux basics: what a process is, how processes are related, how they’re told to stop (signals), how files and folders are attached (mounts) and where Linux shows you all of this (/proc).
Everyday example: a company. Every employee (process) has an ID number (PID) and a manager (parent). The CEO (PID 1) is at the top. Memos (signals) tell people to stop work, and the office layout (mounts) decides which rooms each person can walk into.
1. Process, Parent and PID
A process is a running instance of a program. Every process has a unique PID (Process ID).
Every process except PID 1 has a parent, identified by its PPID (Parent Process ID).
PID 1 is the first process the kernel starts at boot (systemd on most systems). It is the ancestor of every other process.
A process starts another with fork() (make a copy of itself) followed by exec() (replace the copy with the new program). That’s why children inherit their parent’s environment variables, open files and permissions.
If a parent dies first, its child becomes an orphan and is adopted by PID 1.
A finished process whose parent hasn’t collected its exit status yet is a zombie. PID 1 is responsible for cleaning up (“reaping”) zombies.
2. Watching and controlling processes
ps aux # all processes, all users
ps aux --sort=-%mem # biggest memory users first
ps -p -o pid,ppid,cmd # just one process, chosen columns
top # live view (press q to quit)
kill # send SIGTERM (polite stop)
kill -9 # send SIGKILL (force stop)
pkill -f "python app.py" # signal processes by command line
jobs; fg; bg # manage background jobs in your shell
3. Signals: messages to a process
A signal is a small message the kernel delivers to a process. The process can catch it (run its own code), ignore it, or let the default action happen. Two signals can never be caught or ignored: SIGKILL and SIGSTOP.
SIGTERM
- 15
- stop
- the polite “please shut down”. The app can clean up first. kill sends this by default, and so does docker stop.
SIGKILL
- 9
- stop
- the forced stop. Can’t be caught, so no cleanup happens. Last resort only.
SIGINT
- 2
- stop
- what Ctrl+C sends to the program in your terminal.
SIGHUP
- 1
- stop
- originally “the terminal hung up”; many servers (nginx, sshd) treat it as “reload your config”.
SIGSTOP / SIGCONT
- 19 / 18
- pause / resume
- pause and resume a process.
Rule of thumb: always try SIGTERM first, and use SIGKILL only if the process ignores it or is stuck.
Exit codes tell you how a process ended. 0 means success. When a process is killed by a signal, the exit code is 128 + the signal number: 137 = 128 + 9 (SIGKILL), 143 = 128 + 15 (SIGTERM). You’ll see 137 a lot with containers.
4. Mounts: attaching folders
In Linux everything lives in one folder tree starting at /. Disks, USB drives and network shares are attached (”mounted”) onto a folder in that tree.
findmnt # every mount, as a tree
df -h # mounted disks and free space
You’ll attach your own folders into containers with bind mounts i
5. /proc: Linux’s window into every process
/proc isn’t a real folder on disk. The kernel generates it on the fly, with one folder per running process, named by its PID:
ls /proc/$$ # files describing your shell process
cat /proc/$$/status | head # name, state, PID, PPID, memory…
cat /proc/$$/cmdline | tr '\0' ' ' # the exact command line
ls -l /proc/$$/ns # the namespaces this process belongs to
cat /proc/1/cmdline | tr '\0' ' ' # what PID 1 is
Tools like ps and top simply read these files. Inside a container, /proc shows only the container’s own processes.
Content Ref: https://godisai.in/

