<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SystemProgramming | Portfolio</title><link>https://ansangah.github.io/en/tags/systemprogramming/</link><atom:link href="https://ansangah.github.io/en/tags/systemprogramming/index.xml" rel="self" type="application/rss+xml"/><description>SystemProgramming</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en</language><lastBuildDate>Wed, 30 Apr 2025 00:00:00 +0000</lastBuildDate><image><url>https://ansangah.github.io/media/sharing.png</url><title>SystemProgramming</title><link>https://ansangah.github.io/en/tags/systemprogramming/</link></image><item><title>Operating Systems</title><link>https://ansangah.github.io/en/blog/subjects/os/</link><pubDate>Wed, 30 Apr 2025 00:00:00 +0000</pubDate><guid>https://ansangah.github.io/en/blog/subjects/os/</guid><description>&lt;h2 id="1-history-and-concepts"&gt;1. History and Concepts&lt;/h2&gt;
&lt;h3 id="11-batch-processing"&gt;1.1 Batch Processing&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Early OSes executed a single job at a time with no user intervention.&lt;/li&gt;
&lt;li&gt;Operators manually queued jobs; the next job started only after the previous finished.&lt;/li&gt;
&lt;li&gt;Idle CPU time abounded while waiting for I/O, making computation inefficient.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="12-limitations-of-batch"&gt;1.2 Limitations of Batch&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;CPU idle time:&lt;/strong&gt; Fast CPUs waited for slow I/O devices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Slow job switching:&lt;/strong&gt; Manual intervention delayed the transition between jobs.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="13-spooling-fixes-issue-1"&gt;1.3 Spooling (Fixes Issue 1)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Buffers I/O so computation and device work overlap.&lt;/li&gt;
&lt;li&gt;Example: printer spooling—documents are queued on disk; printers fetch at their own pace while the CPU continues other work.&lt;/li&gt;
&lt;li&gt;Benefit: CPU need not stall for I/O completion.&lt;/li&gt;
&lt;li&gt;Caveat: If the program depends immediately on I/O results (e.g., &lt;code&gt;read()&lt;/code&gt;), spooling alone cannot help.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="14-automatic-job-sequencing-fixes-issue-2"&gt;1.4 Automatic Job Sequencing (Fixes Issue 2)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Scheduling software automatically loads the next job as soon as the previous one finishes.&lt;/li&gt;
&lt;li&gt;Improves throughput compared with manual batching.&lt;/li&gt;
&lt;li&gt;Requires &lt;strong&gt;multiprogramming&lt;/strong&gt; to keep multiple jobs resident in memory.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="15-multiprogramming--time-sharing"&gt;1.5 Multiprogramming &amp;amp; Time Sharing&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Multiple jobs reside in memory; CPU switches to another while the current one waits for I/O.&lt;/li&gt;
&lt;li&gt;FCFS plus priority-based policies balance fairness.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time sharing:&lt;/strong&gt; CPU time is sliced so each job sees frequent progress. Heavy context switching gives the illusion of concurrency but adds overhead.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="2-os-and-computer-system-structure"&gt;2. OS and Computer-System Structure&lt;/h2&gt;
&lt;h3 id="21-four-components"&gt;2.1 Four Components&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Hardware:&lt;/strong&gt; CPU, memory, I/O devices provide raw resources.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operating System:&lt;/strong&gt; Arbitrates resource access among programs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application Programs:&lt;/strong&gt; Decide how resources are used to satisfy user tasks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Users:&lt;/strong&gt; People or other systems interacting with the computer.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="22-bus-architecture"&gt;2.2 Bus Architecture&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Early machines used a single bus—CPU, memory, I/O shared one channel—causing bottlenecks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hierarchical dual-bus&lt;/strong&gt; design emerged:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;System bus:&lt;/strong&gt; connects fast CPU/memory.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;I/O bus:&lt;/strong&gt; connects slower peripherals.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Northbridge:&lt;/strong&gt; controller for high-speed devices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Southbridge:&lt;/strong&gt; handles slower devices and legacy ports.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="3-execution-modes-user-vs-kernel"&gt;3. Execution Modes: User vs. Kernel&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;CPUs provide at least two privilege levels for system protection.&lt;/li&gt;
&lt;li&gt;Each mode controls which instructions and memory regions are accessible.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="31-kernel-mode"&gt;3.1 Kernel Mode&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Privileged; OS services, drivers, and resource managers run here with full hardware access.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="32-user-mode"&gt;3.2 User Mode&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Restricted; applications cannot execute privileged instructions and must request services via the OS.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="33-mode-switching"&gt;3.3 Mode Switching&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;System calls, interrupts, and traps flip the mode bit and jump into kernel handlers.&lt;/li&gt;
&lt;li&gt;After handling, control returns to user mode at the interrupted point.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="4-cpu-event-handling"&gt;4. CPU Event Handling&lt;/h2&gt;
&lt;h3 id="41-hardware-interrupts"&gt;4.1 Hardware Interrupts&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Asynchronous events from devices.&lt;/li&gt;
&lt;li&gt;Sequence: save context → jump to ISR → perform service → restore context → resume execution.&lt;/li&gt;
&lt;li&gt;Priorities decide which interrupts pre-empt others; keep ISRs short.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="42-traps-software-interrupts"&gt;4.2 Traps (Software Interrupts)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Synchronous events within a program: e.g., divide-by-zero, system calls.&lt;/li&gt;
&lt;li&gt;Trigger a switch to kernel mode but may reuse existing context without full saving.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="43-io-device-components"&gt;4.3 I/O Device Components&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Bus:&lt;/strong&gt; data, address, and control lines.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Device registers:&lt;/strong&gt; control, status, input, output; mapped to memory for CPU access.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Controller:&lt;/strong&gt; intermediates between devices and buses, arbitrating use.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="5-device-access-methods"&gt;5. Device Access Methods&lt;/h2&gt;
&lt;h3 id="51-io-instructions"&gt;5.1 I/O Instructions&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;CPU-specific instructions communicate directly with devices.&lt;/li&gt;
&lt;li&gt;Non-portable because instruction sets differ.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="52-memory-mapped-io"&gt;5.2 Memory-Mapped I/O&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Maps device registers into the main address space so ordinary loads/stores access hardware.&lt;/li&gt;
&lt;li&gt;Improves portability and programming simplicity.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="6-io-completion-techniques"&gt;6. I/O Completion Techniques&lt;/h2&gt;
&lt;h3 id="61-polling"&gt;6.1 Polling&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;CPU repeatedly checks device status.&lt;/li&gt;
&lt;li&gt;Fast response for quick devices but wastes CPU cycles when waiting.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="62-interrupt-driven-io"&gt;6.2 Interrupt-Driven I/O&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;CPU continues other tasks until a device interrupts to signal completion.&lt;/li&gt;
&lt;li&gt;Saves busy-wait time but incurs context-switch overhead and may delay detection of very fast events.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;&lt;strong&gt;Rule of thumb:&lt;/strong&gt; Fast devices favour polling; slower ones benefit from interrupts.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id="7-data-transfer-methods"&gt;7. Data Transfer Methods&lt;/h2&gt;
&lt;h3 id="71-programmed-io"&gt;7.1 Programmed I/O&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;CPU performs all data movement; expensive for large transfers.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="72-direct-memory-access-dma"&gt;7.2 Direct Memory Access (DMA)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;A DMA controller transfers data between memory and devices on behalf of the CPU.&lt;/li&gt;
&lt;li&gt;Process: CPU issues command → DMA moves data → completion interrupt notifies CPU.&lt;/li&gt;
&lt;li&gt;Pros: frees CPU cycles; excels for high-volume transfers.&lt;/li&gt;
&lt;li&gt;Cons: additional hardware cost and possible bus contention.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="8-os-design-considerations"&gt;8. OS Design Considerations&lt;/h2&gt;
&lt;h3 id="81-general-vs-special-purpose"&gt;8.1 General vs. Special Purpose&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;General-purpose OSes serve diverse workloads; special-purpose OSes target embedded, real-time, or appliance scenarios.&lt;/li&gt;
&lt;li&gt;Balancing performance, fairness, and reliability requires deliberate trade-offs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="82-layering-vs-modularity"&gt;8.2 Layering vs. Modularity&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Layering:&lt;/strong&gt; strict top-down structure; upper layers use lower-layer services only.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modularity:&lt;/strong&gt; independent components communicate through explicit interfaces; freer ordering but demands dependency management.&lt;/li&gt;
&lt;li&gt;Modern OSes blend both: layered architecture populated with modular subsystems for stability and extensibility.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id="9-kernel-structures-and-system-calls"&gt;9. Kernel Structures and System Calls&lt;/h2&gt;
&lt;h3 id="91-system-calls--mode-switch"&gt;9.1 System Calls &amp;amp; Mode Switch&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;User code invokes an API → generates a trap → CPU enters kernel mode → trap handler executes → returns to user mode.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="92-parameter-passing"&gt;9.2 Parameter Passing&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Registers:&lt;/strong&gt; fastest but few parameters fit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory blocks:&lt;/strong&gt; store arguments in memory and pass the address.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stack:&lt;/strong&gt; push arguments in user mode; kernel pops them.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="93-monolithic-kernel"&gt;9.3 Monolithic Kernel&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;All kernel services share one address space.&lt;/li&gt;
&lt;li&gt;Pros: minimal overhead for cross-service calls.&lt;/li&gt;
&lt;li&gt;Cons: tightly coupled; a faulty module can crash the entire kernel.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="94-address-spaces"&gt;9.4 Address Spaces&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Define accessible address ranges. Sharing the same space allows direct referencing; separate spaces reinforce protection boundaries.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="95-microkernel"&gt;9.5 Microkernel&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Decomposes services into user-space servers communicating via IPC.&lt;/li&gt;
&lt;li&gt;Pros: low coupling, easy maintenance, unload unused services.&lt;/li&gt;
&lt;li&gt;Cons: frequent address-space switches and IPC overhead can hurt performance.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="96-hybrid-kernel"&gt;9.6 Hybrid Kernel&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Real-world kernels typically combine monolithic cores with loadable modules or user-space servers, balancing performance and flexibility.&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>