Processes, signals and jobs
Unit 3 of 5 in Operating systems and the command line.
You will be able to list, pause and stop processes and choose the right signal for the job.
Lesson
Every process has an ID and an owner
Each process has a unique non-negative integer called its process ID, assigned when the process is created with fork. Tools like ps and top list processes by that number, and other commands use it to say which process they mean.
A process also carries the user and group identifiers from the last unit, so you can always ask who owns a process and with what rights it runs. Child processes start as copies of their parent, which is why a shell's children inherit its settings.
Signals: a way to tap a process on the shoulder
A signal is a standard message the system or another process can send to a process. Each signal has a default action: for example, terminate the process, ignore it, or stop it. SIGINT is the interrupt from the keyboard. SIGTERM is the polite termination signal, and a program can catch it and shut down cleanly.
SIGKILL and SIGSTOP are different: they cannot be caught, blocked or ignored. That makes SIGKILL the last resort, because the program gets no chance to clean up. A defender tries SIGTERM first and keeps SIGKILL for a process that will not listen.
Jobs: running, pausing and resuming in your shell
Job control is the ability to stop a process's execution and continue it later. The shell associates a job with each pipeline and keeps a table of running jobs, which the jobs command displays. You can send a long command to the background, bring it back to the front, or pause it.
This is the everyday side of processes: knowing how to leave something running while you do other work, and how to get control back.
Key points
- Every process has a unique process ID and owner IDs; ps and top show them.
- Signals are standard messages; SIGTERM asks nicely, SIGKILL cannot be caught.
- Try SIGTERM before SIGKILL so a program can clean up.
- Job control lets the shell pause, resume and background commands.
Sources
- Linux manual page: credentials(7), process identifiers
- Linux manual page: signal(7), overview of signals
- Bash Reference Manual: Job Control Basics
- Linux manual page: fork(2), create a child process
Practice in the labs
Control real processes, then see how a process gets its environment.
- Linux processes, jobs, and signals: ps, top, kill, and job control: You run, list, suspend and stop a harmless process with job control and signals.
- Environment variables and the PATH: You see how a child process inherits variables and how the PATH decides which program runs, a common place for mistakes.
Knowledge check
- Which signal can a program catch to shut down cleanly? Answer: SIGTERM. SIGTERM is a termination request that a program can catch and handle. SIGKILL and SIGSTOP cannot be caught, blocked or ignored (signal(7)).
- Why try SIGTERM before SIGKILL? Answer: SIGKILL gives the program no chance to clean up. Because SIGKILL cannot be caught, the program cannot save its work or release resources. SIGTERM lets it do both.
- What does the shell's job control let you do? Answer: Stop a process and continue it later. The Bash manual defines job control as the ability to selectively stop (suspend) the execution of processes and continue their execution later.
Back to the syllabus or see all classes.