The Process Tree (And Environment, And procfs)#

Process ID (PID) And Parent Process ID (PPID)#

  • Every process has an ID (PID … Process ID)

  • Every process but the first (PID 1) has a parent process)

  • ⟶ process tree

A typical distro’s process tree (simplified)

  • init - nowadays mostly systemd

  • Services

  • User login sessions (console, graphical, network …)

../../../../../../../_images/typical-process-tree.svg

A typical distro’s process tree#

System Calls: getpid(), getppid()#

Technically …

  • A process can ask the kernel about its parent process

  • A process cannot ask the kernel about its children ⟶ has to take care itself

../../../../../../../_images/tree-syscalls.svg
#include <unistd.h>

#include <print>

int main(int argc, char** argv)
{
    std::println("PID: {}", getpid());                // <--- self's PID
    std::println("PPID: {}", getppid());              // <--- parent's PID

    return 0;
}
$ echo $$                                           # <-- PID of the shell itself
$ ./code/sysprog-process-tree
PID: 115971
PPID: 33634