1 / 47

Operating Systems {week 04}

Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems {week 04}. Operating system services (i). An operating system provides services : Program execution Load programs into memory, run/suspend/halt programs, handle/display errors

ranger
Download Presentation

Operating Systems {week 04}

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D. Operating Systems{week 04}

  2. Operating system services (i) • An operating system provides services: • Program execution • Load programs into memory, run/suspend/halt programs, handle/display errors • I/O operations • Seamlessly interact with I/O devices, includingdisks, networks connection, etc. • Filesystem manipulation • Read/write/traverse filesystem directories,read/write files, enforce permissions, search for files

  3. Operating system services (ii) • Other operating system services: • Inter-Process Communications (IPC) • Processes exchange information via shared memory,message passing, sockets, pipes, files, etc. • Often spans multiple computers and networks • Error detection and recovery • Detect errors in CPU, memory, I/O devices,processes, network connections, etc. • Recover from errors gracefully,ensuring correct and consistent operations

  4. Operating system structure (i) • Using a layered approach, the operating system is divided into Nlevels or layers • Layer 0 is the hardware • Layer 1 is often the kernel • Layer N is the top-leveluser interface (GUI) • Each layer uses functionsand services of the layer(or layers) beneath it

  5. Operating system structure (ii) • Also viewas a stackof services

  6. Operating system kernel • The core program running inan operating system is calledthe kernel • When a computer is switched on,a bootstrap program executes from ROM • The bootstrap program initializes the system, then loads the operating system kernel and starts its execution

  7. User and kernel modes • Program instructions run eitherin user mode or in kernel mode • Kernel mode allows the operating systemto protect itself and its system components switch modesvia system calls

  8. System calls via APIs (i) • OS services are available via system calls • System calls are made via an interface calledan Application Program Interface (API) • Common operating system APIs: • Win32 API for Windows • POSIX API for POSIX-based systems,including UNIX, Linux, Mac OS X • Java API for Java Virtual Machine • C/C++ Standard Libraries

  9. System calls via APIs (ii) • Types of system calls include: • Process control (e.g. start/suspend/stop a process) • Debugging information, too • File management • Device management • Information retrieval and maintenance • Current date/time, number of current users, OS version, amount of free memory, process information, etc. • Communications (e.g. IPC, network)

  10. System calls via APIs (iii) • An API hides the implementation details of the underlying operating system • Programmers just need to abide bythe API specifications • How do we change the API orthe operating system servicesthat it offers? the dude abides...

  11. System calls via APIs (iv)

  12. System calls via APIs (v) • Example using the printf()function from C • One API may callanother, which mayin turn call another,and so on...

  13. System calls via APIs (vi) • Use registers to pass parameters: • Store memory location X that references a block of data somewhere in memory

  14. Process scheduling and queues • Processes are created bythe operating system • Processes initially added toa job queue, which containsall processes waiting to enter the system • From the job queue, processes thatare ready for execution are addedto the ready queue

  15. 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

  16. Long-term scheduling (i) • The long-term scheduler isinvoked infrequently

  17. 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

  18. 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

  19. Long-term scheduling (iv) • Most modern operating systems have no long-term scheduler (e.g. Windows, Linux) • All processes are admitted tothe ready queue, regardlessof whether the operatingsystem can handle the load • Often results in userschanging their usage habits....

  20. 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

  21. 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) heap stack data text/code

  22. Process states • As a process executes, it changes its state

  23. Process creation • In Unix, a new child process is forked viathe fork() system call • Child optionally calls the exec() system callto load a new program

  24. 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 memorymanagement information • List of open file/resource handles

  25. Process context switch context switch takes a few milliseconds

  26. Short-term (CPU) scheduling (i) • The short-term scheduler decides which process the CPU executes next • The dispatcher gives control of the CPU to the process selected by the CPU scheduler: • Performs context switch • Switches to user mode • Jumps to the proper location in the user program to resume program execution

  27. Short-term (CPU) scheduling (ii) the dispatcher operates here

  28. CPU-I/O burst cycle (i) • Processes alternate betweenCPU execution and I/O wait • A CPU burst is actual programexecution that uses the CPU • An I/O burst is a blocked state • Each process starts and endswith a CPU burst

  29. CPU-I/O burst cycle (ii) • Histogram of CPU burst time frequencies

  30. CPU scheduling algorithms (i) • CPU scheduling requires an algorithm todetermine which process to dispatch next • Scheduling algorithms include: • First-Come, First-Served (FCFS) • Shortest-Job-First (SJF) • Round-Robin (RR) • Priority • Multilevel Queue (MQ)

  31. process CPU scheduling algorithms (ii) • Preemptive scheduling preempts a running process before itstime slice expires • Or it preempts a processbecause its time slice has expired • Non-preemptive scheduling gives a process exclusive uninterrupted access to the CPU for the entirety of its execution process process process

  32. CPU scheduling algorithms (iii) • Compare scheduling algorithms by measuring • CPU utilization – keep CPU as busy as possible • Throughput – maximize the number of processes that complete their execution per unit time • Turnaround time – minimize the elapsed time to fully execute a particular process • Waiting time – minimize the elapsed time a process waits in the ready queue

  33. P1 P2 P3 0 24 27 30 First-Come-First-Served (FCFS) • FCFS dispatches processesin the order they enterthe ready queue • FCFS is non-preemptive time

  34. P2 P3 P1 0 3 6 30 Shortest-Job-First (SJF) • SJF dispatches processes byselecting the process withthe lowest CPU burst time • SJF is non-preemptive (and predictive) time

  35. SJF with varied arrival times • What happenswhen processesarrive at differentarrival times? • Calculate the turnaround times and wait times for each process • Calculate the average turnaround time and average wait time

  36. P1 P2 P3 P2 P4 P1 11 16 0 2 4 5 7 Preemptive SJF • Same as SJF, but anew process maypreempt therunning process time

  37. Limitations of SJF (i) • SJF is the optimal solution • The problem with SJF is the inability toknow the required CPU burst times • Apply a prediction algorithm that usesprevious CPU burst times • Algorithm uses exponential averaging: • tn = actual length of the nth CPU burst • τn+1 = predicted value for the next CPU burst • τn+1 = α tn + (1 – α) τn , where 0 < α < 1

  38. Limitations of SJF (ii) α is ½

  39. Limitations of SJF (iii) α is ¾ α is ½ α is ¼

  40. Practice! • Apply the FCFS, SJF, and Preemptive SJF scheduling algorithms to this table: • Calculate the wait and turnaround times ofeach process, as well as overall averages recalculate using context switch time tcs = 20 μs

  41. P3 P1 P2 P3 P1 P3 P1 0 2 4 6 8 10 12 13 Round-Robin (RR) • RR is a preemptive algorithmthat gives all ready processesa fair time slice of CPU time • Using a time slice of 2 ms.... time

  42. Priority Scheduling (i) • Associate a priority number with each process • The dispatcher selects the processwith the highest priority • For multiple ready processeswith identical priority values,use FCFS (or ...) • Key problem is starvation • Overcome starvation by aging, increasingthe priority of a process as it ages

  43. process Priority Scheduling (ii) • Is priority scheduling preemptiveor non-preemptive? • Non-preemptive priority scheduling places higher-priority processes at the head of the queue • Preemptive priority scheduling requires a running process to be interrupted and preempted upon the arrival of a higher-priority process

  44. Multiclass systems • Operating systems that support priority schemes are often called multiclass systems use a separate schedulingalgorithm for each queue

  45. Multilevel Queue (MQ) • Assign processes to multiple queues,each with its own scheduling algorithm

  46. Multilevel Feedback Queue (MFQ) • Dynamically assign processes to multiple queues based on actual CPU burst times • i.e. feedback quantum is synonymouswith time slice

  47. Practice! • Apply the FCFS, SJF, RR, and Preemptive Priority scheduling algorithms to this table: • For RR, use a time slice of 10 ms • Calculate the wait and turnaround times ofeach process, as well as overall averages lower number indicates a higher priority recalculate using context switch time tcs = 20 μs

More Related