operating systems { week 02}
DESCRIPTION
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems { week 02}. from Principles of Modern Operating Systems , 1st edition by Garrido and Schlesinger, Jones and Bartlett Publishers, 2008, ISBN 0-7637-3574-4. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/1.jpg)
Operating Systems{week 02}
Rensselaer Polytechnic InstituteCSCI-4210 – Operating SystemsDavid Goldschmidt, Ph.D.
from Principles of Modern Operating Systems, 1st edition by Garrido and Schlesinger, Jones and Bartlett Publishers, 2008, ISBN 0-7637-3574-4
![Page 2: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/2.jpg)
Multiprogramming and timesharing
Multiprogramming goals: Maximize CPU utilization Maximize number of processes in
memory
Timesharing goals: Switch CPU among processes such that
users interact with each program simultaneously
Maximize fairness
almost!
![Page 3: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/3.jpg)
Process scheduling and queues
Processes are created bythe operating system Processes initially added to
a job queue, which containsall processes waiting to enter the system
From the job queue, processes thatare ready for execution are addedto the ready queue
![Page 4: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/4.jpg)
Schedulers
A long-term scheduler (i.e. job scheduler) selects processes from the job queue, adding those processes to the ready queue
A short-term scheduler (i.e. CPU scheduler) selects processes from the ready queueand allocates time with the CPU More on this later....
![Page 5: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/5.jpg)
Long-term scheduling (i)
The long-term scheduler isinvoked infrequently
![Page 6: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/6.jpg)
Long-term scheduling (ii)
The degree of multiprogramming ofan operating system is defined asthe number of processes in memory In a stable operating system,
the average process arrival rate equalsthe average process departure rate
![Page 7: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/7.jpg)
Long-term scheduling (iii) Processes are either I/O bound or CPU
bound A CPU-bound process does little I/O and
instead makes heavy use of the CPU An I/O-bound process spends a majority of
itstime performing (i.e. waiting for) I/O
The long-term scheduler should select a good process mix of CPU-bound and I/O-bound processes
![Page 8: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/8.jpg)
Long-term scheduling (iv)
Most modern operating systems have no long-term scheduler (e.g. Windows, UNIX) All processes are admitted to
the ready queue, regardlessof whether the operatingsystem can handle the load
Often results in userschanging their usage habits....
![Page 9: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/9.jpg)
Medium-term scheduling
Modern operating systems implement a medium-term scheduler to swap processes to/from memory and disk
![Page 10: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/10.jpg)
Processes (i)
A process is an active program in execution Requires CPU time, memory, file access,
network access, other I/O access
Operating system is responsible for: Creating/deleting processes Scheduling processes Allocating resources to processes Synchronizing communication between
processes
![Page 11: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/11.jpg)
Processes (ii)
For each process, the operatingsystem manages and executesprocesses by recording: Program counter (PC) Registers Data section (global data) Stack (temporary data) Heap
(dynamically allocated memory)
![Page 12: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/12.jpg)
Process states
As a process executes, it changes its state
![Page 13: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/13.jpg)
Process control block
Operating system represents each process via a process control block (PCB) Process state Process ID or number Program counter (PC) CPU registers CPU-scheduling and memory
management information List of open file/resource handles
![Page 14: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/14.jpg)
Process context switch
context switch takesa few milliseconds
![Page 15: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/15.jpg)
Process scheduling
![Page 16: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/16.jpg)
Short-term scheduling
The short-term scheduler frequently decides which process the CPU executes next Typical time slice (t) a process has with
the CPU is 100 milliseconds How much CPU time is wasted
if t is 100ms and it takes 10msto schedule the next processand perform the context switch?
![Page 17: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/17.jpg)
Process creation (i)
Processes are created from other processes A parent process creates a child process,
whichin turn creates child processes of its own, etc.
A tree of processes is the result:
![Page 18: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/18.jpg)
Process creation (ii)
Operating system resources are sometimes shared amongst processes
Possibilities: Parent and child processes share all
resources Child shares a subset of its parent’s
resources Parent and child processes share no
resources
![Page 19: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/19.jpg)
Process creation (iii)
Each process has itsown unique processidentifier (pid)
![Page 20: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/20.jpg)
Process creation (iv)
When a new process is created,the parent has two options: Parent process continues to execute
concurrently with its children Parent process waits for its children to
terminate their execution
The child process decides what it will do: Duplicate the parent or load a new program
![Page 21: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/21.jpg)
Process creation (v)
In Unix, a new child process is forked viathe fork() system call
Child optionally calls the exec() system callto load a new program
![Page 22: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/22.jpg)
What next?
Read and study Chapters 1 and 2
Do Exercises at the end of Chapter 2
Also be sure to do the programming exercise on the next slide in C
![Page 23: Operating Systems { week 02}](https://reader035.vdocument.in/reader035/viewer/2022062305/56815a35550346895dc77539/html5/thumbnails/23.jpg)
Programming exercise
Implement a program to simulate caching: Write a function called calculateAnswer() that
takes integer n as input and calculates (and returns)the sum (1 + 2 + … + n) ▪ Pretend this method is computationally costly!
Initially, the cache is empty▪ Ask the user to input a number in range 1..100 ▪ If the answer is not in the cache, call calculateAnswer() and display the resulting sum; store the result in the cache
▪ If the answer is in the cache, simply display the answer
Did it work?