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
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Introduction to Operating Systems.
Lesson complete
Earn the 3 college credits for Introduction to Operating Systems
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: CPU Scheduling →← 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 →
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.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: Linux vs Operating Systems
Why take it here
Why students take Introduction to Operating Systems with UPI Study
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.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →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?
What is the degree of multiprogramming?
What is swapping in an operating system?
What is the difference between I/O-bound and CPU-bound processes?
About the Introduction to Operating Systems course
How many college credits is Introduction to Operating Systems?
How much does Introduction to Operating Systems cost and what is included?
Which universities accept UPI Study credits?
How long does Introduction to Operating Systems take?
How are the exams done?
How do my credits reach my college?
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
3 credits · NCCRSEnroll →