diff --git a/.obsidian/graph.json b/.obsidian/graph.json index 872109c..0006b10 100644 --- a/.obsidian/graph.json +++ b/.obsidian/graph.json @@ -46,6 +46,6 @@ "repelStrength": 10, "linkStrength": 1, "linkDistance": 250, - "scale": 0.9981011873358133, + "scale": 0.6697358161023433, "close": false } \ No newline at end of file diff --git a/.obsidian/plugins/obsidian-icon-folder/data.json b/.obsidian/plugins/obsidian-icon-folder/data.json index d149e6e..9bb8c11 100644 --- a/.obsidian/plugins/obsidian-icon-folder/data.json +++ b/.obsidian/plugins/obsidian-icon-folder/data.json @@ -92,5 +92,5 @@ "Operating Systems": "🖥", "Introduction to Machine Learning": "🤖", "Introduction to Machine Learning/Introductory lecture.md": "LiInfo", - "Operating Systems/Introductory lecture.md": "LiInfo" + "Operating Systems/Overview.md": "LiInfo" } \ No newline at end of file diff --git a/.obsidian/types.json b/.obsidian/types.json index 92b1fae..0efa87e 100644 --- a/.obsidian/types.json +++ b/.obsidian/types.json @@ -22,6 +22,7 @@ "excalidraw-css": "text", "excalidraw-autoexport": "text", "excalidraw-embeddable-theme": "text", - "excalidraw-open-md": "checkbox" + "excalidraw-open-md": "checkbox", + "backlinks": "multitext" } } \ No newline at end of file diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json new file mode 100644 index 0000000..2e9345e --- /dev/null +++ b/.obsidian/workspace.json @@ -0,0 +1,273 @@ +{ + "main": { + "id": "0e274d9edc8c2fe9", + "type": "split", + "children": [ + { + "id": "d34eff5233313e79", + "type": "tabs", + "children": [ + { + "id": "33904cc196ca322b", + "type": "leaf", + "state": { + "type": "markdown", + "state": { + "file": "Operating Systems/Processes and Threads.md", + "mode": "source", + "source": false + }, + "icon": "lucide-file", + "title": "Processes and Threads" + } + }, + { + "id": "f1e9c17a4ce43dc1", + "type": "leaf", + "state": { + "type": "markdown", + "state": { + "file": "Languages & Machines/Introduction.md", + "mode": "source", + "source": false + }, + "icon": "lucide-file", + "title": "Introduction" + } + } + ] + } + ], + "direction": "vertical" + }, + "left": { + "id": "14a8ed1946809664", + "type": "split", + "children": [ + { + "id": "92972e07e7778c7e", + "type": "tabs", + "children": [ + { + "id": "56bef0584922cba9", + "type": "leaf", + "state": { + "type": "file-explorer", + "state": { + "sortOrder": "alphabetical", + "autoReveal": false + }, + "icon": "lucide-folder-closed", + "title": "Files" + } + }, + { + "id": "919f0d89f8f5c3bb", + "type": "leaf", + "state": { + "type": "search", + "state": { + "query": "", + "matchingCase": false, + "explainSearch": false, + "collapseAll": false, + "extraContext": false, + "sortOrder": "alphabetical" + }, + "icon": "lucide-search", + "title": "Search" + } + }, + { + "id": "b590c125634ae7e4", + "type": "leaf", + "state": { + "type": "bookmarks", + "state": {}, + "icon": "lucide-bookmark", + "title": "Bookmarks" + } + } + ] + } + ], + "direction": "horizontal", + "width": 234.5 + }, + "right": { + "id": "fd4347e6b5300816", + "type": "split", + "children": [ + { + "id": "5d827a80e07e299e", + "type": "tabs", + "children": [ + { + "id": "10adbcc903d0c352", + "type": "leaf", + "state": { + "type": "backlink", + "state": { + "file": "Extracurricular/Circuitree/Committee Market/discussion/Macro pad.md", + "collapseAll": false, + "extraContext": false, + "sortOrder": "alphabetical", + "showSearch": false, + "searchQuery": "", + "backlinkCollapsed": false, + "unlinkedCollapsed": true + }, + "icon": "links-coming-in", + "title": "Backlinks for Macro pad" + } + }, + { + "id": "d61fc22784bbd3b0", + "type": "leaf", + "state": { + "type": "outgoing-link", + "state": { + "file": "Extracurricular/Circuitree/Committee Market/discussion/Macro pad.md", + "linksCollapsed": false, + "unlinkedCollapsed": true + }, + "icon": "links-going-out", + "title": "Outgoing links from Macro pad" + } + }, + { + "id": "c6317bbbe070400b", + "type": "leaf", + "state": { + "type": "tag", + "state": { + "sortOrder": "frequency", + "useHierarchy": true + }, + "icon": "lucide-tags", + "title": "Tags" + } + }, + { + "id": "9fea917e949ad714", + "type": "leaf", + "state": { + "type": "outline", + "state": { + "file": "Extracurricular/Circuitree/Committee Market/discussion/Macro pad.md" + }, + "icon": "lucide-list", + "title": "Outline of Macro pad" + } + }, + { + "id": "e195b03d8630d307", + "type": "leaf", + "state": { + "type": "QUICKSHARE_SIDE_VIEW", + "state": {}, + "icon": "lucide-file", + "title": "Plugin no longer active" + } + }, + { + "id": "ac10c8e987c0e736", + "type": "leaf", + "state": { + "type": "git-view", + "state": {}, + "icon": "git-pull-request", + "title": "Source Control" + } + }, + { + "id": "9a5124aa0b3cede4", + "type": "leaf", + "state": { + "type": "transcript-view", + "state": {}, + "icon": "lucide-file", + "title": "Plugin no longer active" + } + } + ], + "currentTab": 5 + } + ], + "direction": "horizontal", + "width": 200, + "collapsed": true + }, + "left-ribbon": { + "hiddenItems": { + "switcher:Open quick switcher": false, + "graph:Open graph view": false, + "canvas:Create new canvas": false, + "daily-notes:Open today's daily note": false, + "templates:Insert template": false, + "command-palette:Open command palette": false, + "obsidian-excalidraw-plugin:Create new drawing": false, + "table-editor-obsidian:Advanced Tables Toolbar": false, + "obsidian-git:Open Git source control": false, + "obsidian-advanced-slides:Show Slide Preview": false, + "omnisearch:Omnisearch": false + } + }, + "active": "56bef0584922cba9", + "lastOpenFiles": [ + "Operating Systems/assets/Pasted image 20250419143713.png", + "Operating Systems/Overview.md", + "Languages & Machines/Introduction.md", + "Operating Systems/Processes and Threads.md", + "Operating Systems/assets/Pasted image 20250419141856.png", + "unicef.org.md", + "Software Engineering/TA Meeting 1.md", + "conflict-files-obsidian-git.md", + "Software Engineering/Reqirements.md", + "Software Engineering/Meeting.md", + "Software Engineering/Initial Questions.md", + "Languages & Machines/assets/Pasted image 20250414190229.png", + "Languages & Machines/assets/Pasted image 20250414190144.png", + "Languages & Machines/assets/Pasted image 20250414190119.png", + "Languages & Machines/assets/Pasted image 20250414190100.png", + "Languages & Machines/assets/Pasted image 20250113151159.png", + "Languages & Machines/assets", + "Languages & Machines/Regular languages.md", + "Languages & Machines", + "Extracurricular/Circuitree/Antenna Building/Idea and proposed timeline.md", + "Extracurricular/Circuitree/Antenna Building", + "Fundamentals of Electronics/Introductory Lecture.md", + "Introduction to Machine Learning/Introductory lecture.md", + "Fundamentals of Electronics", + "Pasted image 20250113151159.png", + "Advanced Algorithms/Graph Algorithms.md", + "Advanced Algorithms/Graphs.md", + "Introduction to Machine Learning/image.png", + "Extracurricular/Circuitree/Committee Market/Macro pad.md", + "Extracurricular/Circuitree/Committee Market/discussion/Committee market ideas.md", + "Extracurricular/Circuitree/Committee Market/discussion/CA.md", + "Extracurricular/Misc/Plan.md", + "Extracurricular/Misc/Proposed Routine Plan.canvas", + "Extracurricular/Misc/Ideas.md", + "Functional Programming/Eq and Num.md", + "Functional Programming/Proofs.md", + "Discrete Structures/Relations and Digraphs.md", + "Operating Systems/assets/Pasted image 20250204103541.png", + "Software Engineering/Introductory Lecture.md", + "Discrete Structures/Recurrence relations.md", + "Introduction to Machine Learning", + "Operating Systems/assets/image.png", + "Operating Systems/assets", + "Operating Systems", + "Software Engineering", + "Discrete Structures/Midterm", + "Untitled.canvas", + "Excalidraw", + "Web Engineering/canvae/server_client.canvas", + "Advanced Programming/projects/second/Refactoring.canvas", + "Advanced Programming/assets/assignment/assignment_organization.canvas", + "Advanced Programming/assets/spring/Beans.canvas", + "Advanced Programming/assets/assignment/assignment_app.canvas", + "Extracurricular/Circuitree/Committee Market/discussion/Proposed showcase infra.canvas" + ] +} \ No newline at end of file diff --git a/Operating Systems/Introductory lecture.md b/Operating Systems/Overview.md similarity index 100% rename from Operating Systems/Introductory lecture.md rename to Operating Systems/Overview.md diff --git a/Operating Systems/Processes and Threads.md b/Operating Systems/Processes and Threads.md new file mode 100644 index 0000000..5cd077c --- /dev/null +++ b/Operating Systems/Processes and Threads.md @@ -0,0 +1,201 @@ +--- +type: theoretical +backlinks: + - "[[Overview#Multiprogramming]]" + - "[[Overview#Multitasking/Timesharing]]" +--- +## Process +A program in execution. + +Consists of: +* The program code - **text section** +* Current activity - **PC**, registers +* **Stack** -> Function parameters, return addresses, local variables +* Data section +* **Heap** -> dynamically allocated (at run time) memory + + +The difference between a process and a program is that the program is the executable file stored on disk, while the process **is running** (shocker). + + +### Creation +Four events could cause processes to be created +1. System init - Daemons +2. Executing a process by "running a program" +3. A user process request to create a new process +4. Initiation of a batch[^1] job + + +### `fork()` + +A Linux [system call](Overview.md#System%20calls). + +```mermaid +graph LR; + + A["`fork()`"] --> |parent| B["wait"] + A --> |child|C["`exec()`"] + C --> D["`exit()`"] + D --> B + B --> E["Resumes"] +``` + + +### Hierarchy +Linux creates a parent-child relationship between processes, Windows doesn't. + +Linux: + +```mermaid +graph TD; + init["init + pid = 1"] + + login["login + pid = 8415"] + + kthreadd["kthreadd + pid = 2"] + + sshd["sshd + pid=3028"] + + + bash["bash + pid=8416"] + + + ps["ps + pid=9298"] + + emacs["emacs + pid=9204"] + + khelper["khelper + pid=6"] + + pdflush["pdflush + pid=200"] + +init --> login +init --> kthreadd +init --> sshd + +login --> bash + +bash --> ps +bash --> emacs + +kthreadd --> khelper +kthreadd --> pdflush + + +``` + + +### Termination +1. Normal + Process should return a code to its parent. Child processes should wait until they know that the parent received it, becoming **zombie processes**. If the parent dies before the child, the child is called an orphan. Absolutely fucking crazy naming. Every linux process should have a parent process [source: unicef](https://unicef.org). +2. Error - just a special return code +3. Fatal error, involuntary - division by zero, invalid opcode; process is immediately terminated by the system +4. Killed + + +### States +As a state machine + +1. Running +2. Ready +3. Blocked (blocking == waiting) + +```mermaid +graph TD; + A["Running"] + B["Ready"] + C["Blocked"] + + A --> |1| C + A --> |2| B + B --> |3| A + C --> |4| B +``` +#### Ready State +- In this state the process is not waiting for a resoucrce +- Can be executed +- Put in a queue (ready queue) + +#### I/O queue +- I/O device has its own +- Multiple queues are created by OS +## Timesharing: In-depth +from [Multitasking/Timesharing](Overview.md#Multitasking/Timesharing) +The output of running programs should not change when we stop and switch back to the same program later on. + + +### Context switching +Switching implies that we have to store the values of registers, flags, PC, etc. of the current process and load them into the next one. Then we continue. + + +### The process control block - PCB +The OS needs a place to store the status of each process. This is that data structure. + + +### Process table +A list of PCBs (one per process) + +![Figure: PS](Pasted%20image%2020250419141856.png) + + +* Timer (`ISR`[^2]) generates multiple interrupts per second +* Store the status of the process in PCB + + + +## Threads +A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set of registers, ( and a thread ID. ) + +A light-weight process. + +![](Pasted%20image%2020250419143713.png) + +### Processes vs threads + + +| Processes | Thread | +| ----------------------------------------- | ------------------------------------------------ | +| Heavyweight | Lighter | +| Each process has its own memory | Threads use memory of the process they belong to | +| Inter-Process Communication (IPC) is slow | Way faster inter-thread communication | +| Context switching is more expensive | Less expensive | +| Do not share memory | do share memory | + +### Multithreading +- Traditional processes have a single thread of control[^3] +* If a process has multiple threads of control, it can perform more than one task + +### Ways to Implement Threads +* Kernel-Level Threads (KLT) + * Managed by the OS kernel + * Each thread is a separate scheduling entity + * `pthread`, `thread` +* User-Level Threads (ULT) + * Managed by user-space libraries, OS is unaware + * Faster context switching + * Green threads + +### User Threads and Kernel Threads +- **User threads** + - Implemented by a thread library at the user level + - thread creation and scheduling are done in user space +- **Kernel Threads** + - Managed by OS + +### Relationship modles +* + +[^1]: A batch job is a scheduled task or a set of commands that are executed without manual intervention - **cron** + +[^2]: interrupt service routine - like in LC3 + +[^3]: sequence of programmed instructions that can be managed independently by a scheduler within a computer program + diff --git a/Operating Systems/assets/Pasted image 20250419141856.png b/Operating Systems/assets/Pasted image 20250419141856.png new file mode 100644 index 0000000..2465359 Binary files /dev/null and b/Operating Systems/assets/Pasted image 20250419141856.png differ diff --git a/Operating Systems/assets/Pasted image 20250419143713.png b/Operating Systems/assets/Pasted image 20250419143713.png new file mode 100644 index 0000000..dd531de Binary files /dev/null and b/Operating Systems/assets/Pasted image 20250419143713.png differ diff --git a/conflict-files-obsidian-git.md b/conflict-files-obsidian-git.md deleted file mode 100644 index d8bbd4f..0000000 --- a/conflict-files-obsidian-git.md +++ /dev/null @@ -1,17 +0,0 @@ -# Conflicts -Please resolve them and commit them using the commands `Git: Commit all changes` followed by `Git: Push` -(This file will automatically be deleted before commit) -[[#Additional Instructions]] available below file list - -- Not a file: .obsidian/workspace.json - -# Additional Instructions -I strongly recommend to use "Source mode" for viewing the conflicted files. For simple conflicts, in each file listed above replace every occurrence of the following text blocks with the desired text. - -```diff -<<<<<<< HEAD - File changes in local repository -======= - File changes in remote repository ->>>>>>> origin/main -``` \ No newline at end of file diff --git a/unicef.org.md b/unicef.org.md new file mode 100644 index 0000000..e69de29