# so1unp/lab-03-sistemas-operativos-m-a-b architecture

> Architecture diagram of the GitHub repository so1unp/lab-03-sistemas-operativos-m-a-b, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/so1unp/lab-03-sistemas-operativos-m-a-b
- Repository: https://github.com/so1unp/lab-03-sistemas-operativos-m-a-b

## Overview

##### Project type and purpose
- This is a collection of four command‑line C programs for an operating‑systems laboratory:
- sigcatch.c – intercepts and prints incoming signals
- forkprio.c – creates child processes with varying priorities and coordinates their execution via signals
- sched-threads.c – spawns POSIX threads under different scheduling policies (FIFO, RR, OTHER) writing into a shared buffer
- benchmark.c – measures and compares the cost of creating processes vs threads
- There is no user‑facing GUI or networked service; each program exercises different kernel subsystems (signals, scheduling, threading, resource accounting).

##### File structure
- Top‑level files:
- .gitignore, .vscode – IDE and VCS configs
- Makefile – build all four executables
- README.md & Ejercicio1.md – project description, requirements, and questions
- benchmark.c, forkprio.c, sched-threads.c, sigcatch.c – source code for each lab exercise
- No “src” or “lib” directories, each C file is a standalone self-contained component.
- No external dependencies beyond libc and pthreads.

##### Extract insights from the README
- Each exercise description enumerates:
- Which system calls to use (sigaction, fork, setpriority, pthread_create, etc.)
- Expected program flow (how processes/threads are created, how signals are sent, how timing and output occur)
- Required output formats and the questions to answer after experimentation

##### Main components
a. User CLI layer
– The shell that invokes each executable with arguments
– sigcatch
– forkprio
– sched-threads
– benchmark
– Exports APIs: fork(), exec(), kill(), sigaction(), pause(), setpriority()/nice(), getpriority(), getrusage(), times(), sleep(), pthread_create(), pthread_join(), pthread_exit()
d. Kernel subsystems
– Signal Manager
– Process Scheduler
– Thread Scheduler (POSIX)
– Resource Accounting (for getrusage/times)
e. Shared data
– stdout (console) for printed output
– In-memory buffer (sched-threads only)

##### Relationships and interactions
- Executable -> System call interface (invoking various syscalls)
- System call interface -> Kernel subsystems (signal delivery, scheduling decisions, thread management)
- Kernel subsystems -> Executable (signal callbacks, scheduling of CPU bursts)
- Executable -> stdout (printing results)

##### Highlighted patterns and principles
- Single‑threaded vs multithreaded execution
- Use of signals as asynchronous callbacks
- Priority inversion and scheduler policy effects (forkprio and sched-threads)
- Benchmarking overhead of process vs thread creation

##### Technologies and libraries
- C99 / POSIX C standard library
- POSIX threads
- Linux kernel scheduler and signal facilities
- GNU Make for build orchestration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User CLI Layer
    CLI["User CLI (shell)"]:::userland
    click CLI "https://github.com/so1unp/lab-03-sistemas-operativos-m-a-b/tree/master/Makefile"

    %% Executables
    subgraph "User‑land Executables"
        direction TB
        sigcatch["sigcatch.c\nSignal handler demo"]:::userland
        forkprio["forkprio.c\nProcess creation & priority demo"]:::userland
        schedthreads["sched‑threads.c\nPOSIX threads & scheduling policies demo"]:::userland
        benchmark["benchmark.c\nProcess vs. thread creation cost measurement"]:::userland
    end
    click sigcatch "https://github.com/so1unp/lab-03-sistemas-operativos-m-a-b/blob/master/sigcatch.c"
    click forkprio "https://github.com/so1unp/lab-03-sistemas-operativos-m-a-b/blob/master/forkprio.c"
    click schedthreads "https://github.com/so1unp/lab-03-sistemas-operativos-m-a-b/blob/master/sched-threads.c"
    click benchmark "https://github.com/so1unp/lab-03-sistemas-operativos-m-a-b/blob/master/benchmark.c"

    %% System Call Interface
    sysif["System Call Interface"]:::syscall

    %% Kernel Subsystems
    subgraph "Kernel Subsystems"
        direction TB
        SignalManager["Signal Manager"]:::kernel
        ProcessSched["Process Scheduler"]:::kernel
        ThreadSched["Thread Scheduler"]:::kernel
        ResourceAcct["Resource Accounting"]:::kernel
    end

    %% Shared Output
    stdout["stdout (console)"]:::userland

    %% In‑memory Buffer
    buffer["Shared Buffer"]:::userland

    %% Connections
    CLI -->|"invokes"| sigcatch
    CLI -->|"invokes"| forkprio
    CLI -->|"invokes"| schedthreads
    CLI -->|"invokes"| benchmark

    sigcatch -->|"sigaction()/pause()"| sysif
    sysif -->|"deliver signals"| SignalManager
    SignalManager -->|"signal callbacks"| sigcatch
    sigcatch -->|"prints results"| stdout

    forkprio -->|"fork()/setpriority()/kill()"| sysif
    sysif -->|"schedule processes"| ProcessSched
    ProcessSched -->|"runs child processes"| forkprio
    forkprio -->|"prints results"| stdout

    schedthreads -->|"pthread_create()/sched_attr"| sysif
    sysif -->|"schedule threads"| ThreadSched
    ThreadSched -->|"runs threads"| schedthreads
    schedthreads -->|"writes results"| buffer
    schedthreads -->|"prints summary"| stdout

    benchmark -->|"fork()/pthread_create()/getrusage()"| sysif
    sysif -->|"process scheduling"| ProcessSched
    sysif -->|"thread scheduling"| ThreadSched
    sysif -->|"report usage"| ResourceAcct
    ResourceAcct -->|"usage data"| benchmark
    benchmark -->|"prints comparison"| stdout

    %% Styles
    classDef userland fill:#e0ffe0,stroke:#2d7a2d,color:#2d7a2d;
    classDef syscall fill:#e0e0ff,stroke:#1f1fa1,color:#1f1fa1;
    classDef kernel fill:#ffe0e0,stroke:#a14444,color:#a14444;
    class CLI,sigcatch,forkprio,schedthreads,benchmark,stdout,buffer userland
    class sysif syscall
    class SignalManager,ProcessSched,ThreadSched,ResourceAcct kernel
```
