Renaming all folders

This commit is contained in:
Fabio Scotto di Santolo
2025-08-22 16:21:42 +02:00
parent 331308b2d8
commit 538cb4559e
45 changed files with 9 additions and 9 deletions

View File

@@ -0,0 +1,52 @@
# 📘 Chapter 6 Advanced Process Management (Summary)
**From _Linux System Programming_ by Robert Love, 2nd Ed.**
---
## 🔄 Process Scheduling
- The kernel scheduler selects **runnable processes** (those not blocked on I/O, etc.).
- Goals: **maximize CPU utilization**, minimize wait time, and ensure fairness :contentReference[oaicite:1]{index=1}.
- Covers **preemptive scheduling**, **timeslices**, and the Linux **Completely Fair Scheduler (CFS)**.
- Explains **processor affinity** and CPU sets: binding processes to specific CPUs for cache performance :contentReference[oaicite:2]{index=2}.
## 🧭 Yielding the Processor
- `sched_yield()` lets a running process give up the CPU voluntarily.
- Useful in busy-wait loops or when expecting immediate CPU from others :contentReference[oaicite:3]{index=3}.
## 🎚️ Priorities & Nice Values
- Processes can adjust their priority using **`nice()`**, where lower nice = higher priority.
- Real-time scheduling policies (`SCHED_FIFO`, `SCHED_RR`) grant stronger priority guarantees for time-sensitive tasks :contentReference[oaicite:4]{index=4}.
## 🧠 Processor Affinity
- **Get/set CPU affinity** with `sched_getaffinity()` and `sched_setaffinity()`.
- Ensures cache affinity, reducing context-switch overhead :contentReference[oaicite:5]{index=5}.
## ⏱️ Real-Time Scheduling
- Differences between **hard** and **soft real-time** systems.
- Configurable policies: `SCHED_FIFO`, `SCHED_RR`, with real-time priority range 099 :contentReference[oaicite:6]{index=6}.
- Care needed: real-time tasks can lead to starvation of normal tasks.
## 🔒 Resource Limits
- Kernel enforces per-process limits via `setrlimit()`/`getrlimit()`:
- CPU usage (`RLIMIT_CPU`)
- File sizes (`RLIMIT_FSIZE`)
- Number of open files, memory, etc. :contentReference[oaicite:7]{index=7}.
- Helps contain rogue or misbehaving processes, essential for robustness.
---
## ✅ Why It Matters
Advanced control over process scheduling, priorities, affinity, and resource limits is critical for writing:
- Real-time or latency-sensitive applications
- High-performance servers that benefit from core binding
- Robust daemons that avoid resource exhaustion
This chapter equips systems programmers with the tools to finely tune how tasks interact with the kernel scheduler and manage system impact.
---
## 📚 References
- *Linux System Programming*, 2nd Ed. — Robert Love
- `man 2 sched_setscheduler`, `man 2 setrlimit`, `man 2 sched_getaffinity`
- Wikipedia: [Completely Fair Scheduler](https://en.wikipedia.org/wiki/Completely_Fair_Scheduler) :contentReference[oaicite:8]{index=8}

View File

@@ -0,0 +1,31 @@
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2025 Fabio Scotto di Santolo
*/
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
int main(void)
{
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(0, &set);
CPU_CLR(1, &set);
int ret = sched_setaffinity(0, sizeof(cpu_set_t), &set);
if (ret == -1) {
perror("sched_setaffinity");
}
for (int i = 0; i < CPU_SETSIZE; i++) {
int cpu = CPU_ISSET(i, &set);
if (cpu) {
printf("cpu=%d is set\n", i);
}
}
return 0;
}

View File

@@ -0,0 +1,25 @@
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2025 Fabio Scotto di Santolo
*/
#include <stdio.h>
#include <sys/resource.h>
#include <unistd.h>
int main(void)
{
int ret;
ret = nice(0);
printf("Current nice by nice function: %d\n", ret);
ret = getpriority(PRIO_PROCESS, 0);
printf("Current nice by getpriority function: %d\n", ret);
if (setpriority(PRIO_PROCESS, 0, 10) == -1) {
perror("setpriority");
return -1;
}
ret = getpriority(PRIO_PROCESS, 0);
printf("Current nice by getpriority function: %d\n", ret);
return 0;
}