ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Operating Systems
    CC-211
    Progress0 / 34 topics
    Topics
    1. Operating Systems Basics2. System Calls3. Process Concept and Scheduling4. Interprocess Communication5. Multithreaded Programming6. Multithreading Models7. Threading Issues8. Process Scheduling Algorithms9. Thread Scheduling10. Multiple-Processor Scheduling11. Synchronization12. Critical Section13. Synchronization Hardware14. Synchronization Problems15. Deadlocks16. Detecting and Recovering from Deadlocks17. Memory Management18. Swapping19. Contiguous Memory Allocation20. Segmentation and Paging21. Virtual Memory Management22. Demand Paging23. Thrashing24. Memory-Mapped Files25. File Systems26. File Concept27. Directory and Disk Structure28. Directory Implementation29. Free Space Management30. Disk Structure and Scheduling31. Swap Space Management32. System Protection33. Virtual Machines34. Operating System Security
    CC-311›Process Concept and Scheduling
    Operating SystemsTopic 3 of 34

    Process Concept and Scheduling

    8 minread
    1,321words
    Intermediatelevel

    Process Concept and Scheduling

    The process concept and scheduling are two fundamental concepts in the field of operating systems. They are critical to understanding how the operating system manages tasks, ensures multitasking, and allocates system resources efficiently. Let’s break these concepts down in detail:


    1. Process Concept

    A process is a program in execution. It represents a unit of work in a system. A process consists of the program code (also called the text section), its current activity (represented by the program counter), the process stack, the heap, and a set of registers that hold values during execution. Processes are the fundamental entities in an operating system that need to be managed.

    Key Components of a Process:

    • Program Code (Text Section): This is the code that defines what the program does. It is the executable part of the process.
    • Program Counter (PC): A register that keeps track of the next instruction to execute.
    • Stack: The stack holds the function calls, local variables, and control flow information (e.g., return addresses).
    • Heap: The heap is used for dynamic memory allocation during program execution.
    • Data Section: This section contains global and static variables used by the program.

    Process States:

    A process can be in one of several states during its execution. These states describe the process’s current activity and determine what the OS can do with it:

    • New: The process is being created.
    • Ready: The process is loaded into memory and ready to run, but it is waiting for CPU time.
    • Running: The process is currently executing on the CPU.
    • Waiting (Blocked): The process is waiting for some event to occur (e.g., waiting for I/O completion or waiting for a resource).
    • Terminated: The process has finished execution or has been killed by the OS.

    Process Control Block (PCB):

    The OS keeps track of processes through a Process Control Block (PCB), which stores all the information necessary to manage a process. Each process has its own PCB, which includes:

    • Process ID (PID)
    • Program Counter
    • CPU Registers
    • Memory Management Information (e.g., base and limit registers)
    • Process state (Ready, Running, Waiting, etc.)
    • Accounting Information (e.g., CPU time used)
    • I/O Status Information (e.g., list of open files)

    The PCB allows the OS to switch between processes, allocate resources, and manage process execution.


    2. Process Scheduling

    Process scheduling refers to the way an operating system decides which process should run on the CPU at any given time. Since multiple processes may be waiting for CPU time, the OS needs to efficiently manage and allocate the CPU to processes in a way that optimizes overall system performance.

    Scheduling is a core function of the operating system that aims to achieve:

    • Fairness: Ensuring that all processes get a fair share of CPU time.
    • Efficiency: Maximizing CPU utilization while ensuring that the system is responsive.
    • Response Time: Minimizing the time a process waits before it gets CPU time (especially important in interactive systems).

    Key Elements of Process Scheduling:

    • Scheduler: The scheduler is a part of the OS that determines which process should execute next. The scheduling process is managed through different levels:
      • Long-Term Scheduler (Job Scheduler): Decides which processes should be brought into memory (from the job pool) for execution. It controls the degree of multiprogramming.
      • Short-Term Scheduler (CPU Scheduler): Decides which process from the ready queue should be executed next by the CPU. This scheduler runs frequently (every few milliseconds).
      • Medium-Term Scheduler: Sometimes used in systems with virtual memory, it handles swapping processes in and out of memory.

    Scheduling Criteria:

    The performance of scheduling algorithms is usually evaluated using several criteria:

    • CPU Utilization: The percentage of time the CPU is actively processing tasks.
    • Throughput: The number of processes completed per unit of time.
    • Turnaround Time: The total time from process submission to completion (including waiting time, execution time, etc.).
    • Waiting Time: The total time a process spends in the ready queue waiting for CPU time.
    • Response Time: The time between submitting a request (e.g., a command) and receiving the first response. This is especially important in interactive systems.
    • Fairness: Ensuring that all processes receive a fair share of CPU time.

    Types of Scheduling Algorithms:

    1. First-Come, First-Served (FCFS):

      • Description: The simplest scheduling algorithm. The first process to arrive gets executed first.
      • Advantages: Simple and easy to implement.
      • Disadvantages: Can cause convoy effects where short processes wait too long if they are preceded by long processes. It also doesn’t minimize waiting time effectively.
    2. Shortest Job Next (SJN) / Shortest Job First (SJF):

      • Description: The process with the shortest CPU burst time (estimated next execution time) is executed first.
      • Advantages: Can minimize average waiting time.
      • Disadvantages: It is hard to predict the length of the next CPU burst. It can also lead to starvation (where long processes may never get executed).
    3. Round Robin (RR):

      • Description: Each process gets a fixed time slice (quantum) to execute. Once the time slice expires, the process is preempted and placed at the end of the ready queue.
      • Advantages: Fair and ensures that all processes get CPU time.
      • Disadvantages: If the time quantum is too large, it behaves like FCFS. If it’s too small, it can lead to excessive context switching and reduced efficiency.
    4. Priority Scheduling:

      • Description: Each process is assigned a priority, and the process with the highest priority is executed first. In case of ties, the system can use other criteria like FCFS.
      • Advantages: Allows for the prioritization of important processes.
      • Disadvantages: Can lead to starvation of lower-priority processes if higher-priority processes keep arriving.
    5. Multilevel Queue Scheduling:

      • Description: Processes are grouped into multiple queues based on their priority or type (e.g., interactive, batch). Each queue has its own scheduling algorithm.
      • Advantages: It helps organize processes better based on their needs.
      • Disadvantages: Processes can be "stuck" in their queues, leading to inefficiency in certain cases.
    6. Multilevel Feedback Queue Scheduling:

      • Description: A dynamic version of the multilevel queue scheduling. Processes can move between queues based on their behavior (e.g., if a process uses too much CPU time, it’s moved to a lower-priority queue).
      • Advantages: Combines the benefits of multilevel queue scheduling and feedback for better fairness and responsiveness.
      • Disadvantages: Complex to implement.
    7. Earliest Deadline First (EDF) (Real-Time Scheduling):

      • Description: In real-time systems, processes are assigned deadlines, and the process with the earliest deadline is executed first.
      • Advantages: Ensures real-time processes meet their deadlines.
      • Disadvantages: Complex and may not be feasible for systems with a large number of processes.

    3. Preemptive vs. Non-Preemptive Scheduling

    • Preemptive Scheduling: In this type of scheduling, a running process can be interrupted and moved to the ready queue by the scheduler if a higher-priority process arrives or if the time slice expires. This ensures that all processes get a fair share of the CPU.

      • Example: Round Robin, Priority Scheduling.
    • Non-Preemptive Scheduling: In this type of scheduling, once a process starts executing, it runs until it finishes or voluntarily yields the CPU (e.g., waiting for I/O). There is no interruption from the scheduler.

      • Example: First-Come, First-Served (FCFS), Shortest Job First (SJF).

    4. Context Switching

    When the operating system switches between processes, the state of the current process is saved, and the state of the next process to be executed is loaded. This process is called context switching.

    The steps involved in a context switch are:

    1. Save the state (CPU registers, program counter) of the currently running process.
    2. Load the state of the next process from its Process Control Block (PCB).
    3. Update the process state (e.g., from Running to Ready or from Waiting to Ready).

    Context switching introduces overhead due to the need to save and restore process states, but it's necessary for multitasking and efficient CPU utilization.


    5. Conclusion

    The process concept and scheduling are central to the management of a computer system. The operating system must handle processes, allocate resources, and schedule them efficiently to ensure fairness, responsiveness, and optimal performance. Understanding process states, scheduling algorithms, and their respective advantages and drawbacks helps to understand how operating systems function in real-world scenarios.

    Previous topic 2
    System Calls
    Next topic 4
    Interprocess Communication

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time8 min
      Word count1,321
      Code examples0
      DifficultyIntermediate