{"id":502,"date":"2026-06-21T20:39:11","date_gmt":"2026-06-21T20:39:11","guid":{"rendered":"https:\/\/paknoteshub.online\/?page_id=502"},"modified":"2026-06-21T20:40:06","modified_gmt":"2026-06-21T20:40:06","slug":"operating-system","status":"publish","type":"page","link":"https:\/\/paknoteshub.online\/?page_id=502","title":{"rendered":"Operating System"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"502\" class=\"elementor elementor-502\">\n\t\t\t\t<div class=\"elementor-element elementor-element-6d67493 e-flex e-con-boxed e-con e-parent\" data-id=\"6d67493\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-ece344c elementor-widget elementor-widget-html\" data-id=\"ece344c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t\t<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n  <meta charset=\"UTF-8\"\/>\r\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\/>\r\n  <title>Operating Systems \u2013 University Level \u2013 Pak Notes Hub<\/title>\r\n  <link href=\"https:\/\/fonts.googleapis.com\/css2?family=Inter:wght@400;500;600;700&family=Fira+Code:wght@400;500&display=swap\" rel=\"stylesheet\"\/>\r\n  <style>\r\n    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\r\n    :root {\r\n      --green: #1a7a4a; --green-dark: #145f38; --green-light: #e8f5ee;\r\n      --teal: #17a589; --accent: #f0b127; --dark: #1c2833; --mid: #566573;\r\n      --light: #f4f6f7; --code-bg: #f0f4f8; --code-border: #2e86c1;\r\n      --note-bg: #fef9e7; --note-border: #f0b127; --white: #ffffff;\r\n      --radius: 10px; --shadow: 0 4px 24px rgba(26,122,74,.10);\r\n    }\r\n    html { scroll-behavior: smooth; }\r\n    body { font-family: 'Inter', sans-serif; background: #f2f6f3; color: var(--dark); line-height: 1.7; font-size: 15px; }\r\n\r\n    \/* NAV *\/\r\n    nav { position: sticky; top: 0; z-index: 100; background: var(--green-dark); padding: 0 2rem; display: flex; align-items: center; justify-content: space-between; height: 56px; box-shadow: 0 2px 12px rgba(0,0,0,.25); }\r\n    .nav-brand { color: #fff; font-weight: 700; font-size: 1.05rem; }\r\n    .nav-brand span { color: #a9dfbf; }\r\n    .nav-links { display: flex; gap: 1.2rem; }\r\n    .nav-links a { color: #d5f5e3; font-size: .85rem; font-weight: 500; text-decoration: none; transition: color .2s; }\r\n    .nav-links a:hover { color: #fff; }\r\n\r\n    \/* HERO *\/\r\n    .hero { background: linear-gradient(135deg, var(--green) 0%, #145f38 60%, #0d4527 100%); padding: 5rem 2rem 4rem; text-align: center; position: relative; overflow: hidden; }\r\n    .hero::before { content: '\u2699'; position: absolute; right: 6%; top: 50%; transform: translateY(-50%); font-size: 9rem; font-family: 'Times New Roman', serif; color: rgba(255,255,255,.06); font-weight: 700; pointer-events: none; }\r\n    .hero-tag { display: inline-block; background: rgba(255,255,255,.12); color: #a9dfbf; font-size: .78rem; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; padding: .35rem 1rem; border-radius: 100px; margin-bottom: 1.2rem; border: 1px solid rgba(169,223,163,.3); }\r\n    .hero h1 { color: #fff; font-size: clamp(1.8rem, 5vw, 3rem); font-weight: 700; line-height: 1.15; margin-bottom: .8rem; }\r\n    .hero h1 span { color: #a9dfbf; }\r\n    .hero p { color: #d5f5e3; font-size: 1.05rem; max-width: 600px; margin: 0 auto 2rem; }\r\n    .hero-pills { display: flex; flex-wrap: wrap; justify-content: center; gap: .7rem; }\r\n    .pill { background: rgba(255,255,255,.13); color: #e8f5ee; padding: .45rem 1.1rem; border-radius: 100px; font-size: .82rem; font-weight: 500; border: 1px solid rgba(255,255,255,.18); }\r\n\r\n    \/* LAYOUT *\/\r\n    .page-wrap { max-width: 940px; margin: 0 auto; padding: 2.5rem 1.5rem 4rem; display: grid; grid-template-columns: 235px 1fr; gap: 2.5rem; align-items: start; }\r\n\r\n    \/* SIDEBAR *\/\r\n    .sidebar { position: sticky; top: 72px; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }\r\n    .sidebar-title { background: var(--green); color: #fff; font-size: .75rem; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; padding: .85rem 1.1rem; }\r\n    .toc-list { list-style: none; padding: .5rem 0; max-height: calc(100vh - 130px); overflow-y: auto; }\r\n    .toc-list li a { display: flex; align-items: center; gap: .55rem; padding: .4rem 1.1rem; color: var(--mid); font-size: .81rem; font-weight: 500; text-decoration: none; transition: all .18s; border-left: 3px solid transparent; }\r\n    .toc-list li a:hover, .toc-list li a.active { color: var(--green); background: var(--green-light); border-left-color: var(--green); }\r\n    .toc-num { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; border-radius: 4px; background: var(--green-light); color: var(--green); font-size: .7rem; font-weight: 700; flex-shrink: 0; }\r\n    .toc-list li a.active .toc-num { background: var(--green); color: #fff; }\r\n\r\n    \/* UNIT CARD *\/\r\n    .unit { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 2.5rem; overflow: hidden; scroll-margin-top: 72px; }\r\n    .unit-header { background: linear-gradient(100deg, var(--green) 0%, #1d9560 100%); padding: 1.4rem 1.8rem; }\r\n    .unit-num-badge { background: rgba(255,255,255,.18); color: #a9dfbf; font-size: .72rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; padding: .3rem .75rem; border-radius: 100px; }\r\n    .unit-header h2 { color: #fff; font-size: 1.25rem; font-weight: 700; line-height: 1.25; margin-top: .35rem; }\r\n    .unit-header p { color: #c8f0d8; font-size: .85rem; margin-top: .2rem; }\r\n    .unit-body { padding: 1.8rem; }\r\n\r\n    \/* HEADINGS & TEXT *\/\r\n    .unit-body h3 { font-size: 1rem; font-weight: 700; color: var(--green); margin: 1.6rem 0 .7rem; padding-left: .85rem; border-left: 3px solid var(--green); line-height: 1.3; }\r\n    .unit-body h3:first-child { margin-top: 0; }\r\n    .unit-body p { color: var(--dark); margin-bottom: .7rem; }\r\n    .unit-body ul { list-style: none; padding: 0; margin: .5rem 0 1rem; }\r\n    .unit-body ul li { padding: .3rem 0 .3rem 1.5rem; position: relative; color: var(--dark); font-size: .93rem; }\r\n    .unit-body ul li::before { content: '\u27a4'; position: absolute; left: 0; color: var(--teal); font-size: .75rem; top: .45rem; }\r\n\r\n    \/* CODE BLOCK *\/\r\n    .code-block { background: var(--code-bg); border-left: 4px solid var(--code-border); border-radius: 6px; padding: 1.1rem 1.3rem; margin: .9rem 0 1rem; overflow-x: auto; }\r\n    .code-block pre { font-family: 'Fira Code', monospace; font-size: .83rem; color: #1a3a54; line-height: 1.75; white-space: pre; }\r\n    .cm { color: #7f8c8d; } .kw { color: #1a5276; font-weight: 600; } .st { color: #1e8449; }\r\n\r\n    \/* TABLES *\/\r\n    .data-table { width: 100%; border-collapse: collapse; margin: .9rem 0 1.2rem; font-size: .87rem; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 6px rgba(0,0,0,.06); }\r\n    .data-table thead th { background: var(--green); color: #fff; padding: .7rem 1rem; text-align: left; font-weight: 600; font-size: .82rem; }\r\n    .data-table tbody tr:nth-child(even) { background: var(--green-light); }\r\n    .data-table tbody tr:hover { background: #d4efdf; }\r\n    .data-table td { padding: .6rem 1rem; border-bottom: 1px solid #dce8e0; vertical-align: top; }\r\n    .data-table td:first-child { font-weight: 600; color: var(--green-dark); }\r\n\r\n    \/* BOXES *\/\r\n    .info-box { background: var(--note-bg); border: 1px solid var(--note-border); border-radius: 7px; padding: .85rem 1.1rem; margin: .9rem 0; font-size: .88rem; line-height: 1.6; color: #7d6608; display: flex; align-items: flex-start; gap: .7rem; }\r\n    .practice { background: var(--green-light); border: 1.5px dashed var(--green); border-radius: 8px; padding: .85rem 1.1rem; margin-top: 1.4rem; color: var(--green-dark); font-size: .88rem; font-weight: 500; }\r\n\r\n    \/* PROGRESS + BACK TOP *\/\r\n    .progress-bar { position: fixed; top: 0; left: 0; height: 3px; background: var(--accent); z-index: 200; transition: width .1s linear; width: 0%; }\r\n    #back-top { position: fixed; bottom: 2rem; right: 2rem; background: var(--green); color: #fff; width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer; font-size: 1.1rem; box-shadow: 0 4px 14px rgba(26,122,74,.35); display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; }\r\n    #back-top.visible { opacity: 1; pointer-events: auto; }\r\n    #back-top:hover { transform: translateY(-2px); }\r\n\r\n    \/* CONGRATS *\/\r\n    .congrats { background: linear-gradient(135deg, var(--green) 0%, #145f38 100%); border-radius: var(--radius); padding: 2.5rem 2rem; text-align: center; color: #fff; margin-bottom: 2.5rem; box-shadow: var(--shadow); }\r\n    .congrats h2 { font-size: 1.8rem; margin-bottom: .5rem; }\r\n    .congrats p { color: #d5f5e3; font-size: 1rem; }\r\n\r\n    @media (max-width: 720px) { .page-wrap { grid-template-columns: 1fr; } .sidebar { position: static; display: none; } .hero::before { display: none; } nav .nav-links { display: none; } }\r\n  <\/style>\r\n<\/head>\r\n<body>\r\n\r\n<div class=\"progress-bar\" id=\"progress\"><\/div>\r\n\r\n<nav>\r\n  <div class=\"nav-brand\">Pak <span>Notes Hub<\/span><\/div>\r\n  <div class=\"nav-links\">\r\n    <a href=\"#unit-1\">Intro<\/a>\r\n    <a href=\"#unit-5\">Process<\/a>\r\n    <a href=\"#unit-9\">Memory<\/a>\r\n  <\/div>\r\n<\/nav>\r\n\r\n<section class=\"hero\">\r\n  <div class=\"hero-tag\">\u2699 University Level \u2014 BS CS \/ BS IT<\/div>\r\n  <h1>Operating Systems<br\/><span>Complete Notes<\/span><\/h1>\r\n  <p>Processes \u00b7 Memory Management \u00b7 File Systems \u00b7 Scheduling \u00b7 Synchronization \u00b7 All in Easy English<\/p>\r\n  <div class=\"hero-pills\">\r\n    <div class=\"pill\">Process Management<\/div>\r\n    <div class=\"pill\">Memory Hierarchy<\/div>\r\n    <div class=\"pill\">Deadlocks<\/div>\r\n  <\/div>\r\n<\/section>\r\n\r\n<div class=\"page-wrap\">\r\n\r\n  <!-- SIDEBAR -->\r\n  <aside class=\"sidebar\">\r\n    <div class=\"sidebar-title\">\ud83d\udcda Table of Contents<\/div>\r\n    <ul class=\"toc-list\">\r\n      <li><a href=\"#unit-1\"><span class=\"toc-num\">1<\/span> Basics<\/a><\/li>\r\n      <li><a href=\"#unit-2\"><span class=\"toc-num\">2<\/span> Process Management<\/a><\/li>\r\n      <li><a href=\"#unit-3\"><span class=\"toc-num\">3<\/span> Process Scheduling<\/a><\/li>\r\n      <li><a href=\"#unit-4\"><span class=\"toc-num\">4<\/span> Process Synchronization<\/a><\/li>\r\n      <li><a href=\"#unit-5\"><span class=\"toc-num\">5<\/span> Deadlocks<\/a><\/li>\r\n      <li><a href=\"#unit-6\"><span class=\"toc-num\">6<\/span> Memory Management<\/a><\/li>\r\n      <li><a href=\"#unit-7\"><span class=\"toc-num\">7<\/span> Virtual Memory<\/a><\/li>\r\n      <li><a href=\"#unit-8\"><span class=\"toc-num\">8<\/span> File Systems<\/a><\/li>\r\n      <li><a href=\"#unit-9\"><span class=\"toc-num\">9<\/span> I\/O Management<\/a><\/li>\r\n      <li><a href=\"#unit-10\"><span class=\"toc-num\">10<\/span> Security<\/a><\/li>\r\n    <\/ul>\r\n  <\/aside>\r\n\r\n  <main>\r\n\r\n    <!-- UNIT 1 -->\r\n    <div class=\"unit\" id=\"unit-1\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 1<\/div>\r\n        <h2>Operating Systems Basics<\/h2>\r\n        <p>Introduction to OS Concepts and Functions<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>What is an Operating System?<\/h3>\r\n        <p>An <strong>Operating System (OS)<\/strong> is system software that manages hardware resources and provides services to applications. It acts as an intermediary between users and hardware.<\/p>\r\n\r\n        <h3>Main Functions of OS<\/h3>\r\n        <ul>\r\n          <li><strong>Resource Management:<\/strong> CPU, Memory, Disk, I\/O devices<\/li>\r\n          <li><strong>Process Management:<\/strong> Create, schedule, terminate processes<\/li>\r\n          <li><strong>Memory Management:<\/strong> Allocate and manage RAM<\/li>\r\n          <li><strong>File Management:<\/strong> Organize and manage files<\/li>\r\n          <li><strong>Security:<\/strong> Protect system from unauthorized access<\/li>\r\n          <li><strong>User Interface:<\/strong> Command-line or graphical interface<\/li>\r\n        <\/ul>\r\n\r\n        <h3>Types of Operating Systems<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Type<\/th><th>Characteristics<\/th><th>Examples<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>Batch OS<\/td><td>Jobs processed in batches, no user interaction<\/td><td>Older mainframe systems<\/td><\/tr>\r\n            <tr><td>Time-Sharing OS<\/td><td>Multiple users share system resources<\/td><td>UNIX, Linux<\/td><\/tr>\r\n            <tr><td>Real-Time OS<\/td><td>Guaranteed response time<\/td><td>Aircraft control, medical devices<\/td><\/tr>\r\n            <tr><td>Distributed OS<\/td><td>Multiple computers networked together<\/td><td>Network systems<\/td><\/tr>\r\n            <tr><td>Embedded OS<\/td><td>Specialized for specific hardware<\/td><td>Android, iOS, Windows Embedded<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>OS Architecture<\/h3>\r\n        <div class=\"code-block\"><pre>User Applications\r\n        \u2193\r\nSystem Call Interface\r\n        \u2193\r\nKernel (Core of OS)\r\n  - Process Management\r\n  - Memory Management\r\n  - File Management\r\n  - I\/O Management\r\n        \u2193\r\nHardware (CPU, Memory, Disk, I\/O)<\/pre><\/div>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> List 3 functions of OS and give real-world examples<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 2 -->\r\n    <div class=\"unit\" id=\"unit-2\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 2<\/div>\r\n        <h2>Process Management<\/h2>\r\n        <p>Creating, Scheduling, and Terminating Processes<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>Process Basics<\/h3>\r\n        <p>A <strong>process<\/strong> is an instance of a program in execution. Each process has its own memory space and resources.<\/p>\r\n\r\n        <h3>Process vs Program<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Program<\/th><th>Process<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>Static code on disk<\/td><td>Dynamic execution in memory<\/td><\/tr>\r\n            <tr><td>One program, one copy<\/td><td>One program, multiple processes possible<\/td><\/tr>\r\n            <tr><td>No resources allocated<\/td><td>Has CPU time, memory, I\/O resources<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>Process States<\/h3>\r\n        <div class=\"code-block\"><pre>\r\nNew \u2192 Ready \u2192 Running \u2192 Waiting \u2192 Terminated\r\n  \u2191_________________________\u2193\r\n     (Context Switch)\r\n\r\nStates:\r\n- New: Process created\r\n- Ready: Waiting for CPU\r\n- Running: Currently executing\r\n- Waiting: Waiting for I\/O or event\r\n- Terminated: Execution complete<\/pre><\/div>\r\n\r\n        <h3>Process Control Block (PCB)<\/h3>\r\n        <p>Data structure that stores information about a process:<\/p>\r\n        <ul>\r\n          <li><strong>PID:<\/strong> Process Identifier<\/li>\r\n          <li><strong>Program Counter:<\/strong> Next instruction address<\/li>\r\n          <li><strong>Registers:<\/strong> Saved register values<\/li>\r\n          <li><strong>Memory:<\/strong> Base and limit registers<\/li>\r\n          <li><strong>I\/O Status:<\/strong> Open files, devices<\/li>\r\n          <li><strong>Priority:<\/strong> Scheduling priority<\/li>\r\n        <\/ul>\r\n\r\n        <h3>Context Switching<\/h3>\r\n        <p><strong>Context switching<\/strong> is saving one process's state and loading another's. Overhead but necessary for multitasking.<\/p>\r\n        <div class=\"info-box\">\ud83d\udca1 Each context switch saves PCB and updates hardware registers. More switches = more overhead!<\/div>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Draw process state diagram and explain each transition<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 3 -->\r\n    <div class=\"unit\" id=\"unit-3\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 3<\/div>\r\n        <h2>CPU Scheduling<\/h2>\r\n        <p>Algorithms for Deciding Which Process Gets CPU Time<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>Scheduling Goals<\/h3>\r\n        <ul>\r\n          <li><strong>Maximize CPU Utilization<\/strong> - Keep CPU busy<\/li>\r\n          <li><strong>Maximize Throughput<\/strong> - Complete more processes<\/li>\r\n          <li><strong>Minimize Turnaround Time<\/strong> - Reduce total execution time<\/li>\r\n          <li><strong>Minimize Waiting Time<\/strong> - Reduce time in ready queue<\/li>\r\n          <li><strong>Minimize Response Time<\/strong> - Quick first response<\/li>\r\n        <\/ul>\r\n\r\n        <h3>Scheduling Algorithms<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Algorithm<\/th><th>Description<\/th><th>Pros\/Cons<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>FCFS<\/td><td>First Come First Served<\/td><td>Simple but can have long waits<\/td><\/tr>\r\n            <tr><td>SJF<\/td><td>Shortest Job First<\/td><td>Optimal but hard to predict<\/td><\/tr>\r\n            <tr><td>Round Robin<\/td><td>Fixed time slice per process<\/td><td>Fair but overhead<\/td><\/tr>\r\n            <tr><td>Priority<\/td><td>Higher priority first<\/td><td>Starvation possible<\/td><\/tr>\r\n            <tr><td>Multi-level Queue<\/td><td>Different queues per priority<\/td><td>More complex<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>FCFS Example<\/h3>\r\n        <div class=\"code-block\"><pre>Processes: P1(24), P2(3), P3(3)  (Burst time in ms)\r\n\r\nTimeline:\r\nP1: 0 -------- 24\r\nP2:           24 -- 27\r\nP3:              27 -- 30\r\n\r\nWaiting Times:\r\nP1: 0, P2: 24, P3: 27\r\nAverage: 17ms<\/pre><\/div>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Compare FCFS vs SJF for the same processes<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 4 -->\r\n    <div class=\"unit\" id=\"unit-4\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 4<\/div>\r\n        <h2>Process Synchronization<\/h2>\r\n        <p>Coordinating Concurrent Processes<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>Critical Section Problem<\/h3>\r\n        <p>When multiple processes access shared data, race conditions occur. <strong>Critical section<\/strong> is code accessing shared data that must execute atomically.<\/p>\r\n\r\n        <h3>Solution Requirements<\/h3>\r\n        <ul>\r\n          <li><strong>Mutual Exclusion:<\/strong> Only one process in critical section<\/li>\r\n          <li><strong>Progress:<\/strong> Processes can't be blocked indefinitely<\/li>\r\n          <li><strong>Bounded Waiting:<\/strong> Limited waits before entering<\/li>\r\n        <\/ul>\r\n\r\n        <h3>Synchronization Tools<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Tool<\/th><th>Description<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>Semaphore<\/td><td>Integer with wait() and signal() operations<\/td><\/tr>\r\n            <tr><td>Mutex<\/td><td>Binary semaphore - locked or unlocked<\/td><\/tr>\r\n            <tr><td>Monitor<\/td><td>High-level construct with entry procedure<\/td><\/tr>\r\n            <tr><td>Lock<\/td><td>Simple mechanism - acquire\/release<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>Semaphore Example<\/h3>\r\n        <div class=\"code-block\"><pre>Semaphore S = 1;  \/\/ Binary semaphore\r\n\r\nProcess P1:          Process P2:\r\nwait(S);             wait(S);\r\n\/\/ Critical Section  \/\/ Critical Section\r\nsignal(S);           signal(S);\r\n\r\nOnly ONE process enters at a time!<\/pre><\/div>\r\n\r\n        <div class=\"info-box\">\ud83d\udca1 <strong>Race Condition:<\/strong> Two processes accessing shared data simultaneously. Result depends on timing - unpredictable!<\/div>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Explain producer-consumer problem and its solution<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 5 -->\r\n    <div class=\"unit\" id=\"unit-5\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 5<\/div>\r\n        <h2>Deadlocks<\/h2>\r\n        <p>When Processes Get Stuck Waiting for Each Other<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>Deadlock Definition<\/h3>\r\n        <p>A <strong>deadlock<\/strong> is a situation where a process waits indefinitely for a resource held by another waiting process. Results in system hang.<\/p>\r\n\r\n        <h3>Conditions for Deadlock (All 4 must exist)<\/h3>\r\n        <ul>\r\n          <li><strong>Mutual Exclusion:<\/strong> Resources can't be shared<\/li>\r\n          <li><strong>Hold and Wait:<\/strong> Processes hold resources while waiting<\/li>\r\n          <li><strong>No Preemption:<\/strong> Resources can't be forcibly taken<\/li>\r\n          <li><strong>Circular Wait:<\/strong> Circular chain of processes<\/li>\r\n        <\/ul>\r\n\r\n        <h3>Deadlock Handling Strategies<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Strategy<\/th><th>Approach<\/th><th>Cost<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>Prevention<\/td><td>Break one of 4 conditions<\/td><td>Low concurrency<\/td><\/tr>\r\n            <tr><td>Avoidance<\/td><td>Banker's algorithm - grant safely<\/td><td>Overhead<\/td><\/tr>\r\n            <tr><td>Detection<\/td><td>Detect deadlock, then recover<\/td><td>Frequent checks<\/td><\/tr>\r\n            <tr><td>Ignorance<\/td><td>Pretend deadlocks don't happen<\/td><td>Manual restart<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>Deadlock Detection<\/h3>\r\n        <p>Wait-for graph: Node = process, edge = wait relationship. Cycle = deadlock.<\/p>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Draw wait-for graph showing deadlock scenario<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 6 -->\r\n    <div class=\"unit\" id=\"unit-6\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 6<\/div>\r\n        <h2>Memory Management<\/h2>\r\n        <p>Allocating and Managing RAM<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>Memory Hierarchy<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Level<\/th><th>Speed<\/th><th>Size<\/th><th>Cost<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>Registers<\/td><td>Fastest<\/td><td>Bytes<\/td><td>Highest<\/td><\/tr>\r\n            <tr><td>L1 Cache<\/td><td>Very Fast<\/td><td>KB<\/td><td>Very High<\/td><\/tr>\r\n            <tr><td>L2 Cache<\/td><td>Fast<\/td><td>MB<\/td><td>High<\/td><\/tr>\r\n            <tr><td>RAM<\/td><td>Medium<\/td><td>GB<\/td><td>Low<\/td><\/tr>\r\n            <tr><td>Disk<\/td><td>Slow<\/td><td>TB<\/td><td>Lowest<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>Memory Allocation Strategies<\/h3>\r\n        <ul>\r\n          <li><strong>Contiguous:<\/strong> Entire process in continuous memory<\/li>\r\n          <li><strong>Paging:<\/strong> Fixed-size pages, can be non-contiguous<\/li>\r\n          <li><strong>Segmentation:<\/strong> Variable-size segments<\/li>\r\n        <\/ul>\r\n\r\n        <h3>Paging<\/h3>\r\n        <p>Divide memory into fixed-size <strong>pages<\/strong> (typically 4KB). Process doesn't need contiguous space.<\/p>\r\n        <div class=\"code-block\"><pre>Logical Address: Page Number | Offset\r\nPhysical Address: Frame Number | Offset\r\n\r\nExample: 4KB pages\r\nLogical address 8000 \u2192 Page 1 (8000\/4096) + Offset (8000%4096)<\/pre><\/div>\r\n\r\n        <div class=\"info-box\">\ud83d\udca1 <strong>TLB (Translation Lookaside Buffer):<\/strong> Cache for page table. Speeds up address translation!<\/div>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Calculate page number and offset for given logical address<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 7 -->\r\n    <div class=\"unit\" id=\"unit-7\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 7<\/div>\r\n        <h2>Virtual Memory<\/h2>\r\n        <p>Extending Physical Memory Using Disk<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>Virtual Memory Concept<\/h3>\r\n        <p><strong>Virtual memory<\/strong> allows processes to use more memory than physically available. Unused pages stored on disk.<\/p>\r\n\r\n        <h3>Demand Paging<\/h3>\r\n        <p>Load pages only when needed, not all at once.<\/p>\r\n        <ul>\r\n          <li><strong>Page Hit:<\/strong> Page in memory, fast access<\/li>\r\n          <li><strong>Page Fault:<\/strong> Page on disk, slow access, must load<\/li>\r\n        <\/ul>\r\n\r\n        <h3>Page Replacement Algorithms<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Algorithm<\/th><th>How It Works<\/th><th>Performance<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>FIFO<\/td><td>Replace oldest page first<\/td><td>Poor - Belady's anomaly<\/td><\/tr>\r\n            <tr><td>LRU<\/td><td>Replace least recently used<\/td><td>Good - approximates optimal<\/td><\/tr>\r\n            <tr><td>Optimal<\/td><td>Replace page used furthest in future<\/td><td>Perfect but impractical<\/td><\/tr>\r\n            <tr><td>Clock<\/td><td>Circular queue with use bit<\/td><td>Good - practical<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>Working Set<\/h3>\r\n        <p>Set of pages actively used by process. OS tries to keep working set in memory to minimize faults.<\/p>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Compare page faults for FIFO vs LRU with example<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 8 -->\r\n    <div class=\"unit\" id=\"unit-8\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 8<\/div>\r\n        <h2>File Systems<\/h2>\r\n        <p>Organizing and Managing Data on Disk<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>File System Basics<\/h3>\r\n        <p><strong>File system<\/strong> organizes data into files and directories. Manages storage space and retrieval.<\/p>\r\n\r\n        <h3>File Attributes<\/h3>\r\n        <ul>\r\n          <li><strong>Name:<\/strong> Human-readable identifier<\/li>\r\n          <li><strong>Type:<\/strong> Extension (.txt, .exe, etc.)<\/li>\r\n          <li><strong>Size:<\/strong> Number of bytes<\/li>\r\n          <li><strong>Permissions:<\/strong> Read, write, execute<\/li>\r\n          <li><strong>Timestamps:<\/strong> Creation, modification, access time<\/li>\r\n          <li><strong>Owner:<\/strong> User who created file<\/li>\r\n        <\/ul>\r\n\r\n        <h3>File Organization<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Method<\/th><th>Structure<\/th><th>Best For<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>Contiguous<\/td><td>Sequential blocks<\/td><td>Fixed-size files<\/td><\/tr>\r\n            <tr><td>Linked<\/td><td>Blocks linked with pointers<\/td><td>Variable-size files<\/td><\/tr>\r\n            <tr><td>Indexed<\/td><td>Index table pointing to blocks<\/td><td>Random access<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>Directory Structure<\/h3>\r\n        <ul>\r\n          <li><strong>Single-level:<\/strong> All files in one directory<\/li>\r\n          <li><strong>Two-level:<\/strong> Users have personal directories<\/li>\r\n          <li><strong>Tree-structured:<\/strong> Hierarchical directories<\/li>\r\n        <\/ul>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Explain inode structure in UNIX file system<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 9 -->\r\n    <div class=\"unit\" id=\"unit-9\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 9<\/div>\r\n        <h2>I\/O Management<\/h2>\r\n        <p>Input\/Output Operations and Device Management<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>I\/O Organization<\/h3>\r\n        <div class=\"code-block\"><pre>User Program (I\/O Request)\r\n         \u2193\r\nI\/O Manager \/ Device Driver\r\n         \u2193\r\nI\/O Controller \/ Hardware\r\n         \u2193\r\nPhysical Device (Disk, Printer, etc.)<\/pre><\/div>\r\n\r\n        <h3>I\/O Techniques<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Technique<\/th><th>How It Works<\/th><th>Speed<\/th><th>CPU Usage<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>Polling<\/td><td>CPU repeatedly checks device status<\/td><td>Slow<\/td><td>High (Wasteful)<\/td><\/tr>\r\n            <tr><td>Interrupt<\/td><td>Device signals CPU when ready<\/td><td>Fast<\/td><td>Low<\/td><\/tr>\r\n            <tr><td>DMA<\/td><td>Device transfers data directly to memory<\/td><td>Very Fast<\/td><td>None<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <h3>Disk Scheduling Algorithms<\/h3>\r\n        <table class=\"data-table\">\r\n          <thead>\r\n            <tr><th>Algorithm<\/th><th>Strategy<\/th><th>Seek Time<\/th><\/tr>\r\n          <\/thead>\r\n          <tbody>\r\n            <tr><td>FCFS<\/td><td>Service in arrival order<\/td><td>Long<\/td><\/tr>\r\n            <tr><td>SSTF<\/td><td>Shortest seek time first<\/td><td>Short<\/td><\/tr>\r\n            <tr><td>SCAN<\/td><td>Elevator - sweep back and forth<\/td><td>Good<\/td><\/tr>\r\n            <tr><td>C-SCAN<\/td><td>One-way sweep, return to start<\/td><td>Fair<\/td><\/tr>\r\n          <\/tbody>\r\n        <\/table>\r\n\r\n        <div class=\"info-box\">\ud83d\udca1 <strong>DMA (Direct Memory Access):<\/strong> Devices communicate directly with memory without CPU involvement. Much faster!<\/div>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Calculate total seek time for disk requests using different algorithms<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- UNIT 10 -->\r\n    <div class=\"unit\" id=\"unit-10\">\r\n      <div class=\"unit-header\">\r\n        <div class=\"unit-num-badge\">Unit 10<\/div>\r\n        <h2>Security & Protection<\/h2>\r\n        <p>Securing System and Data<\/p>\r\n      <\/div>\r\n      <div class=\"unit-body\">\r\n\r\n        <h3>Security Goals<\/h3>\r\n        <ul>\r\n          <li><strong>Confidentiality:<\/strong> Keep data private<\/li>\r\n          <li><strong>Integrity:<\/strong> Prevent unauthorized changes<\/li>\r\n          <li><strong>Availability:<\/strong> System accessible when needed<\/li>\r\n        <\/ul>\r\n\r\n        <h3>User Authentication<\/h3>\r\n        <ul>\r\n          <li><strong>Password:<\/strong> Something you know<\/li>\r\n          <li><strong>Biometric:<\/strong> Something you are<\/li>\r\n          <li><strong>Physical Token:<\/strong> Something you have<\/li>\r\n        <\/ul>\r\n\r\n        <h3>Access Control<\/h3>\r\n        <ul>\r\n          <li><strong>DAC (Discretionary):<\/strong> Owner controls permissions<\/li>\r\n          <li><strong>MAC (Mandatory):<\/strong> System enforces security policy<\/li>\r\n          <li><strong>RBAC (Role-based):<\/strong> Permissions based on role<\/li>\r\n        <\/ul>\r\n\r\n        <h3>File Permissions (Unix)<\/h3>\r\n        <div class=\"code-block\"><pre>rwxrwxrwx\r\n\u251c\u2500 Owner (User)\r\n\u251c\u2500 Group\r\n\u2514\u2500 Others\r\n\r\nr = read (4)\r\nw = write (2)\r\nx = execute (1)\r\n\r\nExample: 755 = rwxr-xr-x\r\nOwner: read+write+execute (7)\r\nGroup: read+execute (5)\r\nOthers: read+execute (5)<\/pre><\/div>\r\n\r\n        <div class=\"practice\"><strong>\u270f\ufe0f Practice:<\/strong> Convert permission codes and explain security implications<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <!-- CONGRATS -->\r\n    <div class=\"congrats\">\r\n      <h2>\ud83c\udf89 Congratulations!<\/h2>\r\n      <p>You've completed the Operating Systems course! Master these concepts and ace your exams!<\/p>\r\n    <\/div>\r\n\r\n    <p style=\"text-align: center; color: var(--mid); font-size: .85rem; padding-bottom: 1rem;\">\r\n      \ud83d\udcda Pak Notes Hub \u2014 Operating Systems Complete Notes | University Level | BS CS \/ BS IT<br>\r\n      For corrections and suggestions: support@paknoteshub.com\r\n    <\/p>\r\n  <\/main>\r\n<\/div>\r\n\r\n<button id=\"back-top\" onclick=\"window.scrollTo({top:0,behavior:'smooth'})\">\u2191<\/button>\r\n\r\n<script>\r\n  const progress = document.getElementById('progress');\r\n  window.addEventListener('scroll', () => {\r\n    const scrollPercent = (window.scrollY \/ (document.documentElement.scrollHeight - window.innerHeight)) * 100;\r\n    progress.style.width = scrollPercent + '%';\r\n    document.getElementById('back-top').classList.toggle('visible', window.scrollY > 400);\r\n  });\r\n  \r\n  document.querySelectorAll('.unit').forEach(unit => {\r\n    const observer = new IntersectionObserver(entries => {\r\n      entries.forEach(entry => {\r\n        if(entry.isIntersecting) {\r\n          const id = entry.target.id;\r\n          document.querySelectorAll('.toc-list a').forEach(a => {\r\n            a.classList.toggle('active', a.href.endsWith(id));\r\n          });\r\n        }\r\n      });\r\n    }, { rootMargin: '-20% 0px -70% 0px' });\r\n    observer.observe(unit);\r\n  });\r\n<\/script>\r\n<\/body>\r\n<\/html>\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Operating Systems \u2013 University Level \u2013 Pak Notes Hub Pak Notes Hub Intro Process Memory \u2699 University Level \u2014 BS CS \/ BS IT Operating SystemsComplete Notes Processes \u00b7 Memory Management \u00b7 File Systems \u00b7 Scheduling \u00b7 Synchronization \u00b7 All in Easy English Process Management Memory Hierarchy Deadlocks \ud83d\udcda Table of Contents 1 Basics 2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_angie_page":false,"footnotes":""},"class_list":["post-502","page","type-page","status-publish","hentry"],"_hostinger_reach_plugin_has_subscription_block":false,"_hostinger_reach_plugin_is_elementor":false,"_links":{"self":[{"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/pages\/502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paknoteshub.online\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=502"}],"version-history":[{"count":4,"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/pages\/502\/revisions"}],"predecessor-version":[{"id":507,"href":"https:\/\/paknoteshub.online\/index.php?rest_route=\/wp\/v2\/pages\/502\/revisions\/507"}],"wp:attachment":[{"href":"https:\/\/paknoteshub.online\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}