Processes: states and PIDs

What a process is as opposed to a program, the PID and PPID, the process tree, the ready, running, blocked and terminated states, the zombie, and reading ps output.

  • 27 cards
  • 4 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link
  4. Scenarios

A few cards from the deck

  • Process: what is it?

    Show the answer

    A running execution of a program, with its own memory, its open files and an identifier the kernel gave it.

    A program is an inert file on disk; launching it twice creates two separate processes, each with its own memory and PID.

  • In this output of ps -o pid,ppid,stat,cmd, which PIDs are descendants of shell 2140, direct or not?

    ```text
    PID PPID STAT CMD
    2140 980 Ss -bash
    2201 2140 S sleep 600
    2305 2140 Sl python3 serveur.py
    2310 2305 S python3 serveur.py
    2388 2140 Z [convert] <defunct>
    2400 980 Ss -bash
    `

    • 2201, 2305, 2310 and 2388
    • 2201, 2305 and 2388: only direct children count
    • 2201, 2305, 2310, 2388 and 2400
    • 2305 and 2310: the others are not descendants
    Show the answer

    2201, 2305, 2310 and 2388

    2310 has 2305 as its parent, which itself has 2140 as its parent: it is a grandchild, hence a descendant. 2400 is another shell, a child of 980 like 2140.

  • A process waiting for a disk read to finish is …; when the read is done, it becomes … again and must still be elected to run.

    Show the answer

    A process waiting for a disk read to finish is blocked; when the read is done, it becomes ready again and must still be elected to run.

    A process never goes from blocked to running: the end of the I/O makes it ready, and the scheduler then chooses who gets the processor.

  • PID: what is it?

    Show the answer

    A unique integer that designates a process for as long as it exists.

    The kernel hands it out at launch; it is the number you give to kill or ps -p to target a process. The first process of the system, systemd on most Linux distributions, has PID 1.

  • ps shows dozens of [worker] <defunct> lines, all children of process 3120, which is still running. kill -9 on them changes nothing. What is the cause?

    • The children are blocked on a disk read; you must wait for it to finish
    • The kernel has no free PIDs left to hand out; the /proc/sys/kernel/pid_max limit must be raised
    • Parent 3120 does not read its children's exit statuses; it must be fixed or restarted
    • The children received SIGSTOP; kill -CONT on each will resume them
    Show the answer

    Parent 3120 does not read its children's exit statuses; it must be fixed or restarted

    A zombie is already dead: no signal reaches it. Only its reaping by the parent removes it. Terminating the parent also works: PID 1 adopts the zombies and reaps them.