Chapter 28: Process Creation & Program Execution

Chapter 28: Process Creation & Program Execution
In More Detail — Process Accounting, clone(), Performance & Attribute Inheritance
6
Topics
15+
Code Examples
30+
Interview Q&As
TLPI
Chapter 28

What You Will Learn

This chapter dives deep into Linux process creation internals. You will understand how the kernel tracks processes via process accounting, how clone() is the real engine behind threads and fork(), how to measure and compare process creation speed, and exactly which attributes a child process inherits or resets during fork() and exec(). These are critical topics for Linux systems programming interviews and production work.

Key Concepts

process accounting acct() acct structure clone() CLONE_VM CLONE_FILES CLONE_THREAD CLONE_SIGHAND CLONE_NEWNS NPTL LinuxThreads fork() vs vfork() vs clone() exec() attribute inheritance thread groups TID / TGID futex containers namespaces comp_t waitpid flags

Chapter Topics

📋 28.1 — Process Accounting

Learn how the Linux kernel records resource usage for every process that terminates. Understand the acct structure, acct() system call, comp_t encoding, and how to read accounting files programmatically.

acct() system call acct structure fields comp_t encoding acct_v3 format accounting flags /proc/sys/kernel/acct
🔧 28.2 — The clone() System Call

Understand clone(), the low-level primitive behind all Linux threads and processes. Learn how it differs from fork() and how threading libraries use it internally.

clone() signature child stack setup child function termination signal vs fork() / vfork()
🚩 28.2.1 — The clone() flags Argument

A deep dive into every important clone() flag — CLONE_VM, CLONE_FILES, CLONE_THREAD, CLONE_SIGHAND, CLONE_NEWNS, and more. Understand exactly what each flag shares between parent and child.

CLONE_VM CLONE_FILES CLONE_FS CLONE_SIGHAND CLONE_THREAD CLONE_NEWNS CLONE_SETTLS containers namespaces
⏳ 28.2.2 — Extensions to waitpid() for Cloned Children

Learn the special waitpid() flags needed to wait for children created by clone() — __WCLONE, __WALL, and __WNOTHREAD — and understand when each is needed.

__WCLONE __WALL __WNOTHREAD clone child vs normal child
⚡ 28.3 — Speed of Process Creation

Benchmark and compare fork(), vfork(), and clone() performance. Understand why vfork() and clone() are faster, and why the difference shrinks once exec() is involved.

fork() cost vfork() speed clone() performance page table copying exec() overhead
📊 28.4 — Effect of exec() and fork() on Process Attributes

A complete reference of all process attributes and what happens to them across fork() and exec(). Covers file descriptors, signals, timers, IPC, capabilities, threads, and more.

inherited attributes reset attributes close-on-exec signal dispositions file locks capabilities

Recommended Learning Path

1. Process Accounting
2. clone() Basics
3. clone() Flags
4. waitpid Extensions
5. Speed Comparison
6. Attribute Inheritance

Ready to Master Linux Process Internals?

Start with Process Accounting and work through each topic in order for the best understanding.

Start Chapter 28 → EmbeddedPathashala

Leave a Reply

Your email address will not be published. Required fields are marked *