Job Scheduling, Explained | Introduction to Operating Systems

UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 2.5 Free with a free account

Job Scheduling

Introduction to Operating Systems · Chapter 2: Process Management: Scheduling, Multitasking, and System CallsSection 2.5 · lesson 14 of 837 min · free with a free account

← MultitaskingNext lesson: CPU Scheduling →

A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

In this lesson

How long-term, short-term, and medium-term schedulers share memory and CPU.

  • Explain why a computer needs schedulers to share scarce resources
  • Compare the long-term, short-term, and medium-term schedulers
  • Trace jobs through admission, swapping, and execution in a small memory
  • Explain why a mix of I/O-bound and CPU-bound jobs keeps a system busy

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (918 words). Read along, or search it.

Opening Question

Forty Print Jobs at Once

Ivy, who looks after the computers at a school, has the same problem every Monday morning. At eight fifty-five, the library printer receives forty jobs. Some are one page. One is a whole yearbook. Who goes first? Whoever came first? The smallest job? The teacher's? Every computer faces this question many times a second. And it asks it at three different levels.

Purpose

Fewer Resources Than Wishes

A computer has fewer resources than it has wishes: one CPU core, a limited amount of memory, one disk. When more programs want them than there are of them, something has to decide who gets what, and in what order. That decision maker is a scheduler. A good one keeps the expensive parts busy, especially the CPU. It treats jobs fairly, and it doesn't let anyone wait forever. People use schedulers too. A hospital sees emergencies before sprained ankles. It doesn't go in strict arrival order.

Analogy

Host, Waiter, and Manager

Think of a restaurant. At the door, a host decides which waiting parties may come in at all, because there are only so many tables. Inside, a waiter decides which table to serve next. And when the room gets too crowded, a manager asks a party that's still reading the menu to wait in the lobby, then calls them back later. Operating systems have the same three jobs.

Three Schedulers

Long-Term, Short-Term, and Medium-Term

The long-term scheduler, also called the job scheduler, chooses which waiting jobs are allowed into memory. That sets the degree of multiprogramming: how many jobs are in memory at once. It runs rarely, seconds or minutes apart, so it can afford to think. The short-term scheduler, or CPU scheduler, picks which ready job runs next. It runs constantly, after every time slice or request, so it must be extremely fast. The medium-term scheduler steps in when memory gets crowded. It moves a job that can't run right now, say one waiting for a slow disk, out to disk. Later it brings the job back. That's called swapping, and other jobs use the freed memory in the meantime.

Common Mistake

Entering Memory Versus Getting the CPU

Don't mix up job scheduling and CPU scheduling. Job scheduling decides which jobs may enter memory. CPU scheduling decides which of the jobs already in memory runs on the CPU right now. Phones and laptops barely use the long-term kind, because you open programs by hand. But they use the short-term kind constantly.

Trace Step One

Admitting Jobs Into Eight Units

Here's a tiny computer with eight units of memory. Five jobs wait in a pool, in order. J1 needs three units, J2 four, J3 three, J4 two, and J5 five. Each job needs one step of CPU time to finish. And at step two, J2 will get stuck, waiting for a slow disk read. Step one. The long-term scheduler admits J1 and J2. Three plus four is seven, which fits in eight. It doesn't admit J3, because seven plus three is ten, more than eight. Then the short-term scheduler runs J1, which finishes, and frees its memory.

Trace Step Two

Swapping Out a Stuck Job

Step two. With J1 gone, J3 fits: four plus three is seven. J4 still wouldn't fit. But J2 is stuck, waiting on the disk, so the medium-term scheduler swaps J2 out. That frees four units. So J4 is admitted, and the short-term scheduler runs J3.

Trace Final Steps

Every Job Finishes Exactly Once

Step three. J2's data has arrived, and there's room, so J2 is swapped back in, and J4 runs. Step four, J2 runs. Step five, J5 finally fits. It's admitted, and it runs. Notice that no job was lost or skipped. Each one finished exactly once. A small Python program printed this same trace, step by step.

Job Mix

I/O-Bound and CPU-Bound Jobs

The long-term scheduler also tries to admit a good mix of jobs. An I/O-bound job spends most of its time waiting for disks, networks or people, and uses the CPU in short bursts. A chat program is like this. A CPU-bound job crunches numbers for a long time between waits, like a video export. With only CPU-bound jobs, the disks sit idle. With only I/O-bound jobs, the CPU sits idle. A mix keeps both busy.

Quick Check

Making Room for Job C

Quick check, with a new machine. Memory holds eight units. Job A, using five, is stuck waiting for a network reply. Job B, using two, is ready to run. The next job in the pool, C, needs four. What should happen so that C can get in? Pause, and decide. A goes out to disk, and C comes in. A is stuck waiting for the network, so it can't use the CPU anyway. Moving its five units out leaves B's two. Two plus four is six, which fits in eight. Moving B out fails twice. B is ready to run, and freeing two units leaves five plus four, nine, still too many.

Real Example

Printer Queues and Browser Tabs

Back to Ivy's Monday printer. Deciding how many of the forty jobs to take in at once is long-term work. Picking which job prints next is short-term work, and lesson 2.6 compares the rules for it: first come, smallest first, and more. And when the old laptop of Sam, who runs a small online bakery, opens twenty browser tabs and the disk light flashes, that's swapping: memory is nearly full. Closing a few tabs frees memory and ends the swapping. That usually helps far more than a faster CPU would.

Key Takeaways

Three Schedulers, Three Roles

To recap. A scheduler decides who gets a scarce resource, and in what order. The long-term scheduler admits jobs to memory. The short-term scheduler picks the next job for the CPU. The medium-term scheduler swaps jobs out to disk, and back, when memory is short. And a mix of CPU-bound and I/O-bound jobs keeps every part busy.

About Introduction to Operating Systems at UPI Study

Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About Job Scheduling

What is the difference between long-term, short-term, and medium-term schedulers?
The long-term scheduler decides which waiting jobs enter memory, the short-term scheduler picks which ready job runs next on the CPU, and the medium-term scheduler swaps jobs out to disk and back when memory is crowded. The long-term one runs rarely and can afford to think, while the short-term one runs constantly and must be extremely fast.
What is the degree of multiprogramming?
The degree of multiprogramming is the number of jobs held in memory at once. The long-term scheduler, also called the job scheduler, controls it by deciding which waiting jobs to admit. On a machine with 8 units of memory, jobs needing 3 and 4 units can both be admitted, but a third job needing 3 more would not fit.
What is swapping in an operating system?
Swapping is moving a job that cannot run right now out of memory to disk, then bringing it back later, so other jobs can use the freed memory. The medium-term scheduler does it, ideally choosing a job that is stuck waiting, such as one waiting for a slow disk or a network reply. A busy disk light with many browser tabs open is often a sign of swapping.
What is the difference between I/O-bound and CPU-bound processes?
An I/O-bound job spends most of its time waiting for disks, networks, or people and uses the CPU in short bursts, like a chat program. A CPU-bound job computes for long stretches between waits, like a video export. With only CPU-bound jobs the disks sit idle, and with only I/O-bound jobs the CPU sits idle, so a mix keeps both busy.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Introduction to Operating Systems.

83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Introduction to Operating Systems
3 credits · NCCRS
Enroll →