Linux processes, signals and permissions
EasyLinuxProcessesSignals
How do processes and signals work in Linux, and how do file permissions work?
TL;DR
A process is a running program with a PID, a parent (PPID), an owner, and a state: running, sleeping, uninterruptible sleep (D, usually waiting on disk or network I/O), stopped, or zombie (finished, but the parent hasn't collected its exit status). Signals are how you talk to processes: SIGTERM (15) asks a process to shut down gracefully, SIGKILL (9) kills it immediately and can't be caught, and SIGHUP often means "reload config". Permissions are read, write and execute bits for owner, group and others, such as rwxr-x--- = 750.
Key points
- Inspect with
ps aux,top/htop,pstree, and/proc/<pid>/. - Graceful shutdown: send
SIGTERM, wait, thenSIGKILL. Kubernetes and Docker do exactly this (30 s and 10 s grace periods by default). - In containers the app runs as PID 1, which gets no default signal handlers. Use exec-form
CMDor a tiny init (tini) soSIGTERMreaches the app. - Zombies use no resources except a PID-table entry; the fix is in the parent. Orphans are adopted by PID 1.
- Permission numbers:
r=4,w=2,x=1. On a directory,xmeans you can enter it. - Special bits: setuid (run as the file's owner), sticky bit on
/tmp(only the owner can delete their files). - Run services as non-root users, and grant only what they need.
Example
bash
ps -eo pid,ppid,stat,user,cmd | grep myapp
kill -TERM 1234 # graceful
kill -KILL 1234 # last resort
chmod 640 app.env # owner rw, group r, others none
chown app:app app.envCommon follow-ups
- What does load average mean? The average number of processes running or waiting to run (including
Dstate) over 1, 5 and 15 minutes. Compare it to the CPU core count. - How do you find what's using a port?
ss -ltnporlsof -i :8080.
What interviewers look for
Tip
SIGTERM vs SIGKILL and why graceful shutdown matters, process states, and reading and setting permissions confidently.
- Red flag:
kill -9as the first move, orchmod 777to "fix" permissions.