Files
system-programming/chp5/README.md
Fabio Scotto di Santolo 883456d095 Added README files
2025-07-01 10:56:08 +02:00

74 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 📘 Chapter 5 Process Management (Summary)
**Based on _Linux System Programming_ by Robert Love**
This chapter covers how Linux manages processes, including their creation, execution, and termination. It introduces key system calls and concepts that underpin multitasking and process control in Unix-like systems.
---
## 🧠 Core Concepts
- A **process** is an independent program with its own memory and execution context.
- The kernel provides **process abstraction** to manage concurrency.
- Processes are scheduled and isolated using virtual memory and process control blocks (PCBs).
---
## 🛠️ Process Creation & Termination
- `fork()` creates a new process (child) by duplicating the calling (parent) process using **copy-on-write**.
- `exec()` replaces the current process image with a new program.
- `wait()` and `waitpid()` allow the parent to wait for and collect the childs exit status.
- `exit()` performs cleanup and exits the process gracefully.
- `_exit()` exits immediately without flushing stdio buffers.
---
## 🔍 Signals & Zombies
- **Zombie processes** occur when a child exits but the parent doesnt read its status with `wait()`.
- `SIGCHLD` is sent to the parent when a child terminates.
- The `init` process (PID 1) will adopt and clean up orphaned children.
---
## 👥 Process Hierarchies
- Every process has a unique **PID** and a **PPID** (parent PID).
- Together they form a **process tree**, starting from `init`.
- Tools like `ps`, `pstree`, and `/proc` are useful for visualizing process hierarchies.
---
## 🎯 Process Identifiers & Groups
- `getpid()` returns the processs ID.
- `getppid()` returns the parents ID.
- **Process groups** and **sessions** enable job control, allowing signals to be sent to multiple related processes.
---
## 🧩 Resource Cleanup
- On termination, the kernel reclaims:
- Memory
- Open file descriptors
- IPC resources
- `exit()` also triggers:
- `atexit()` handlers
- Standard I/O flushes
- Potential creation of core dumps (if enabled)
---
## ✅ Why This Matters
A strong understanding of process control is essential for:
- Writing daemons
- Managing background jobs
- Building shells or supervisors
- Avoiding resource leaks and zombie processes
---
## 📚 References
- _Linux System Programming_, 2nd Edition by Robert Love (O'Reilly)
- `man 2 fork`, `man 2 execve`, `man 2 wait`, `man 2 exit`, `man 7 signal`
---
*This summary is for educational purposes.*