1. Home
  2. Explore
  3. Computer Science
  4. Process Scheduling

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Process Scheduling

Speaker 1Speaker 2

Process Scheduling

10:54
0:00-10:54
  1. Corey

    Welcome to module six. We’re talking about process scheduling. Let’s start with an everyday example: if I schedule a class for nine o’clock, I’m assigning a resource—a classroom—and a time when people can use it.

  2. Anna

    So process scheduling applies that same idea to computing. The resource is the CPU, and the operating system chooses which process gets to use it and when.

  3. Corey

    Exactly. There may be many processes, or threads, waiting in a ready queue, but a computer has a limited number of CPUs. The operating system has to choose a waiting process, give it CPU time, and then make another choice as execution continues.

  4. Anna

    And the challenge isn’t just getting some work done. The system should keep things moving so users don’t feel they’re waiting forever. A mail server, for example, may have enormous numbers of users and processes competing for a limited number of CPUs.

  5. Corey

    Right. A scheduler makes the choice of which process should run next. A dispatcher carries out that choice by handing the CPU to the selected process. The scheduler decides; the dispatcher performs the switch.

  6. Anna

    Why can the operating system switch among processes so effectively? One key is that programs don’t use the CPU continuously. Their execution typically alternates between periods of computation and periods of input or output.

  7. Corey

    Those periods are called CPU bursts and I/O bursts. A process might compute for a while, request disk access, compute again, and then request another I/O operation. I/O generally takes much longer than CPU computation, so the bursts don’t have to be equal in length.

  8. Anna

    Even a simple program that prints “Hello, world” has some computation and then an output operation. The lecture’s broader point is that most programs have both CPU activity and I/O activity, even though a program could, in principle, do no I/O.

  9. Corey

    Suppose there’s only one process. While it’s using the CPU, the disk may be idle. Then the process starts a disk operation, and the CPU may sit idle while that I/O is in progress. When the I/O ends, the process can use the CPU again.

  10. Anna

    But if another process is ready, the CPU doesn’t have to sit idle just because the first process is waiting for disk I/O. It can run the second process’s CPU burst while the first process’s I/O proceeds.

  11. Corey

    And the pattern can continue: when the second process needs I/O, it can wait for the device while the first process returns to the CPU, if it’s ready to run. This overlap lets computation and I/O for different processes make progress at roughly the same time.

  12. Anna

    That’s a major reason to schedule multiple processes. It can improve use of both the CPU and I/O devices, rather than leaving one idle whenever a particular process is waiting on the other.

  13. Corey

    The number of processes admitted into the system at once is called the degree of multiprogramming. They can be in different states—running, ready, or waiting. With four CPUs, at most four processes can be running at one instant, although many more can be ready or waiting.

  14. Anna

    It also helps to distinguish CPU-bound and I/O-bound jobs. A CPU-bound job tends to have substantial computation and potentially long CPU bursts. Matrix multiplication is an example in the lecture: it involves many computations relative to the input and output operations.

  15. Corey

    An I/O-bound job spends relatively more of its time on input and output and often has shorter CPU bursts between I/O bursts. The lecture contrasts matrix addition with matrix multiplication: addition has fewer computations relative to the amount of data read and written.

  16. Anna

    A mix of CPU-bound and I/O-bound work can make scheduling especially useful. While one job waits for I/O, another may use the CPU. The scheduler is coordinating those opportunities.

  17. Corey

    The module describes three scheduling timescales: long-term, medium-term, and short-term. Long-term scheduling is associated with batch work—for example, submitting a large simulation to run overnight and collecting the result later.

  18. Anna

    Short-term scheduling is the rapid decision-making people notice in interactive systems, such as a phone responding when you tap something. The lecture contrasts long-term decisions that may happen on a scale of seconds or minutes with short-term decisions that may happen every millisecond or tens of milliseconds.

  19. Corey

    Medium-term scheduling sits between those timescales. The important idea for this module is that scheduling algorithms can be considered across different kinds of work, while short-term scheduling is especially important for quick interactive response.

  20. Anna

    The CPU scheduler’s choices are connected to process-state changes. A running process might move to waiting when it requests a service, or return to ready if it’s interrupted. A process can move from waiting to ready when the event or service it was waiting for completes.

  21. Corey

    And a process can terminate, either because it has finished or because an exception prevents it from continuing. Those transitions determine which processes are eligible to be scheduled next.

  22. Anna

    That brings us to non-preemptive and preemptive scheduling. In non-preemptive scheduling, once a process has the CPU, the operating system doesn’t forcibly take it away while it’s executing. The process gives up the CPU voluntarily, for example by requesting I/O, or it completes its CPU burst.

  23. Corey

    Preemptive scheduling is different: the operating system can interrupt a running process and take the CPU back. That matters because it can prevent one process from holding the CPU indefinitely while others wait.

  24. Anna

    A process can also stop running because of a trap—for example, dividing by zero or accessing memory in an invalid way. The hardware detects the event and transfers control to an interrupt service routine in the operating system, which can respond to the problem.

  25. Corey

    That kind of event is different from the operating system arranging to preempt a process simply because its time is up. To gain control while a user process is running, the operating system can program a hardware timer. When the timer interrupt occurs, control returns to the operating system, which can make a new scheduling decision.

  26. Anna

    So the timer interrupt is essential to the kind of preemptive scheduling described here. Without a mechanism to interrupt a running process, the operating system can’t reliably force it to give up the CPU.

  27. Corey

    The lecture also calls the voluntary approach cooperative scheduling. The process cooperates by giving up the CPU, such as when it requests I/O or decides it has used enough time. It’s also referred to as non-preemptive scheduling.

  28. Anna

    Preemption helps keep processes from waiting too long, but it introduces other issues too, including coordinating access to shared data and deciding what to do if an interrupt occurs while another interrupt is being handled. Those are questions for later material.

  29. Corey

    There’s also a security connection. If a process can’t be interrupted while it runs, it may have more opportunity to do things before control returns to the operating system. The module flags non-preemptive execution as something to think about in later discussions of operating-system security.

  30. Anna

    Once a scheduling algorithm selects a process, the dispatcher performs the handoff. It saves information about the current process, loads the information for the next one, and switches the context so the selected process can run.

  31. Corey

    The ordering of privilege changes is particularly important. The dispatcher runs as part of the operating system, so it should finish its kernel-level work, switch to user mode, and only then give control to the user program.

  32. Anna

    If control were handed to the user program before switching to user mode, that program could run with kernel privileges. That would be a security vulnerability, because user code would have more authority than it should.

  33. Corey

    The time it takes the dispatcher to stop one process and start another is called dispatch latency. That switching cost is one factor in scheduling, and the lecture notes that it helps distinguish scheduling between processes and between threads.

  34. Anna

    So how do we judge a scheduling algorithm? One measure is CPU utilization: how much of the time the CPU is doing useful work. But maximizing that alone isn’t enough, because one process could keep the CPU busy while others are left waiting.

  35. Corey

    That problem is starvation: a process waits for an excessively long time because other work keeps getting chosen. Throughput is another measure—the number of processes that complete per unit of time—and considering throughput alongside CPU utilization gives a fuller picture.

  36. Anna

    Turnaround time is the total time from a process’s arrival until it finishes: finish time minus arrival time. Waiting time focuses on time spent in the ready queue, waiting for the CPU.

  37. Corey

    For a non-preemptive process that begins running once and then completes, waiting time is its start time minus its arrival time. For a preemptive algorithm, it can leave and re-enter the ready queue, so total waiting time can be calculated as finish time minus arrival time minus the process’s CPU time.

  38. Anna

    And response time is different from turnaround time. It measures how long it takes from submitting a request until the first response—not until the entire job is finished. That early acknowledgment can matter a great deal in an interactive or real-time system.

  39. Corey

    A scheduler has competing goals: maximize CPU utilization and throughput, while minimizing turnaround time, waiting time, and response time. Different algorithms balance these measures differently, and they might aim for a good average or try to limit how bad the worst case can be.

  40. Anna

    Consistency matters too. If response or waiting time varies wildly—very fast one time and very slow the next—users can’t predict what the system will do. Reducing variation can make performance more dependable.

  41. Corey

    The right priorities depend on the system’s purpose. A batch job may care most about throughput or turnaround time. An interactive or real-time system may care especially about response time. Different users can therefore have different ideas of what makes scheduling efficient.

  42. Anna

    So the central idea is that scheduling coordinates limited CPU time with processes that alternate between computation and I/O. The scheduler chooses who runs, and the dispatcher makes the handoff, with the system’s goals determining which performance measures matter most.

  43. Corey

    And we’ve also seen why preemption, timer interrupts, process states, and the secure switch back to user mode matter. Those principles set up the scheduling algorithms we’ll examine next.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent