diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index f63fdf6..cdc543a 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -27,28 +27,16 @@ "state": { "type": "markdown", "state": { - "file": "Software Engineering/Introductory Lecture.md", + "file": "Operating Systems/Introductory lecture.md", "mode": "source", "source": false }, "icon": "lucide-file", - "title": "Introductory Lecture" - } - }, - { - "id": "865543226f144e20", - "type": "leaf", - "state": { - "type": "release-notes", - "state": { - "currentVersion": "1.8.4" - }, - "icon": "lucide-book-up", - "title": "Release Notes 1.8.4" + "title": "Introductory lecture" } } ], - "currentTab": 2 + "currentTab": 1 } ], "direction": "vertical" @@ -226,17 +214,22 @@ "omnisearch:Omnisearch": false } }, - "active": "865543226f144e20", + "active": "3dbe2cc922c4bee2", "lastOpenFiles": [ - "conflict-files-obsidian-git.md", + "Operating Systems/assets/image.png", + "Operating Systems/image.png", + "Operating Systems/assets/Pasted image 20250204103541.png", + "Operating Systems/Introductory lecture.md", + "Operating Systems/assets", + "Pasted image 20250113151159.png", "Software Engineering/Introductory Lecture.md", + "conflict-files-obsidian-git.md", "Untitled.md", "Statistics and Probability/Mock exam run 1.md", "Functional Programming/Proofs.md", "Operating Systems", "Statistics and Probability/Support Lecture.md", "Software Engineering", - "Pasted image 20250113151159.png", "Extracurricular/Misc/Ideas.md", "Functional Programming/Drawing 2024-12-24 17.52.22.excalidraw.md", "Extracurricular/satQuest/Meeting Dec 18.md", @@ -265,16 +258,11 @@ "Extracurricular/satQuest/img/Pasted image 20241206133007.png", "Extracurricular/satQuest/img", "Advanced Algorithms/Recurrence relations.md", - "Advanced Algorithms/Graph Algorithms.md", - "Linear Algebra/Matrices.md", "Advanced Algorithms/assets/pnp/Pasted image 20241203234013.png", - "Advanced Algorithms/assets/pnp/Pasted image 20241203234032.png", - "Advanced Algorithms/assets/graph/1_WR4AtjT_nhwSOtAW99Yd5g.gif", "Advanced Algorithms/assets/pnp", "Advanced Algorithms/assets/graph", "Advanced Algorithms/practicals", "Statistics and Probability/R", - "Discrete Structures/img", "Web Engineering/canvae/server_client.canvas", "Advanced Programming/projects/second/Refactoring.canvas", "Advanced Programming/assets/assignment/assignment_organization.canvas", diff --git a/Operating Systems/Introductory lecture.md b/Operating Systems/Introductory lecture.md new file mode 100644 index 0000000..af59154 --- /dev/null +++ b/Operating Systems/Introductory lecture.md @@ -0,0 +1,192 @@ + +## Operating System +- Manages hardware and software +- Resource allocator + - Manages and routes resources and requests +- Control program + - Prevents errors and improper use + +## User v. System + +### User + +```mermaid +graph TD; + + A["user"] <--> B["application programs"] + B <--> C["operating system"] + C <--> D["computer hardware"] + +``` + + + +### System +An operating system is a control program + + +## Major OS Components + + +| Name | Description | +| ------------------------ | -------------------------------------------------- | +| Kernel | Core part of the OS; manages CPU, memory, I/O | +| Process manager | Handles multitasking, scheduling, and execution | +| Memory Manager | Allocates/deallocates RAM, manages virtual memory. | +| File System | Organizes, stores, and secures files. | +| Device Manager | Interfaces with hardware peripherals | +| User Interface (CLI/GUI) | Allows users to interact with the OS | + + +## Management of resources + +### CPU +- A program can do nothing unless its instructions are executed by a CPU +- An executing program becomes a **process** +- The process needs resources +- All processes can potentially be executed concurrently by multiplexing on one CPU core or in parallel across multiple + + +### Memory +- For a program to be executed, it must be loaded into memory. +- To improve the CPU utilization, several programs are kept in memory. + +OS should: +- Know which parts of memory are currently being used and which process is using htem +- Allocate and deallocate memory accordingly +- Decide which processes and data moves in and out of memory + +### Cache +- Cache operates at different levels (L1, L2, L3) and is managed primarily by hardware (CPU cache controllers), not the operating system. +- **HOWEVER**, the OS can influence this by + - Managing process scheduling which affects cache locality[^1] + - Optimizing memory access patterns + - Supporting cache-aware algorithms[^2] + + +### File System + +- The operating system abstracts from the physical properties of its storage devices to define a logical storage unit, the file + +### Mass Storage +The operating system is responsible for: +- Mounting and unmounting +- Free-space management +- Storage allocation +- Disk scheduling +- Partitioning +- Protection + +### I/O + +The I/O subsystem consists of several components: +- A memory-management component that includes buffering, caching, and spooling +- A general device-driver interface +- Drivers for specific hardware devices + + + + +## User and Operating System Interface +![](Pasted%20image%2020250204103541.png) + + +## Command Interpreters +Special programs that run when a user first logs on. They read and interpret user commands and execute programs. + +On Linux, the command interpreter is called a **shell**. The most common shell is the **Bourne Again Shell (bash)** + +## System calls +- System calls are the interface between the user and the operating system +- They are the only way a user program can request a service from the operating system +- They are typically written in a high-level language (C) and are accessed via a library + +E.g. + +```c +#include +#include + +int main() { + write(1, "Hello, World!\n", 14); // 1 is the file descriptor for stdout, 14 is the number of bytes to write + return 0; +} +``` +![example syscall](assets/image.png) + + +## APIs in the OS + +- APIs are a set of functions that allow the programmer to interact with the OS +- They are typically written in a high-level language (C) and are accessed via a library +- They are used to interact with the OS and its services + + +i.e. Under the hood, widely used libraries like `stdlib.h` and `stdio.h` are just APIs that interact with the OS + + + +## Performance Optimization +A computer system executes a program by: +- Loading the program into memory +- FDE cycle (Fetch, Decode, Execute) +- Repeat until the program is done +- The OS must manage resources to ensure that the program runs efficiently + + +### Instruction Types +- CPU-bound: spends most of its time executing instructions +- I/O-bound: spends most of its time waiting for I/O operations to complete + +Keyword - **waiting**, hence I/O operations are very slow. + +### How do we sped it up? + +- Replace slow I/O devices +- Perform I/O operations independently of the CPU +- Multiprogramming/multitasking + + +#### Spooling +- Simultaneous Peripheral Operations On-Line +- A technique that uses a buffer to hold data for devices that are not currently in use + +```mermaid +graph TD; + + A["User"] --> B["Spooling"] + B --> C["Printer"] + B --> D["Disk"] +``` + +#### Multiprogramming +- The OS keeps several jobs in memory simultaneously +- Needed for efficiency +- Single users cannot keep the CPU and I/O devices busy at all times +- Scheduling is key +- +```mermaid +graph TD; + + A["User"] --> B["Multiprogramming"] + B --> C["Job 1"] + B --> D["Job 2"] +``` + +#### Multitasking/Timesharing +- The OS switches between jobs so quickly that it appears as if they are running simultaneously +- If several jobs are ready to run at the same time, the OS must decide which one to run + +```mermaid +graph TD; + + A["User"] --> B["Multitasking"] + B --> C["Job 1"] + B --> D["Job 2"] +``` + + + +[^1]: is the tendency of a processor to access the same set of memory locations repetitively over a short period of time + +[^2]: https://stackoverflow.com/questions/473137/a-simple-example-of-a-cache-aware-algorithm \ No newline at end of file diff --git a/Operating Systems/assets/Pasted image 20250204103541.png b/Operating Systems/assets/Pasted image 20250204103541.png new file mode 100644 index 0000000..600d567 Binary files /dev/null and b/Operating Systems/assets/Pasted image 20250204103541.png differ diff --git a/Operating Systems/assets/image.png b/Operating Systems/assets/image.png new file mode 100644 index 0000000..b0c3e30 Binary files /dev/null and b/Operating Systems/assets/image.png differ