1 / 70

Workshop 2: Agenda

Workshop 2: Agenda. Homework Review: ch’s 4-7 Study group papers & presentations Lecture & discussion on process types & concepts Group activity on processes and resources Lecture & discussion on resource allocation* Group activity on process management Summary & preview

toshi
Download Presentation

Workshop 2: Agenda

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. Workshop 2: Agenda • Homework Review: ch’s 4-7 • Study group papers & presentations • Lecture & discussion on process types & concepts • Group activity on processes and resources • Lecture & discussion on resource allocation* • Group activity on process management • Summary & preview • *= no graph theory! Operating System Concepts

  2. Workshop 2: Homework Review • Chapter 4: 4.4, 4.5 • Chapter 5: 5.3, 5.9 • Chapter 6: 6.1, 6.8 • Chapter 7: 7.1, 7.3 Operating System Concepts

  3. Study Group Project Operating System Concepts

  4. Module 4: Processes • Process Concept • Process Scheduling • Operation on Processes • Threads • Interprocess Communication Operating System Concepts

  5. Process Concept • An operating system executes a variety of programs: • Batch system – jobs • Time-shared systems – user programs or tasks • PC/Mac -- applications • Textbook uses the terms job and process almost interchangeably. • Process – a program in execution; process execution must progress in sequential fashion. • A process includes: • program counter • stack • data section • Code or text section (may be shared) Operating System Concepts

  6. Diagram of Process State Operating System Concepts

  7. Process Control Block (PCB) Operating System Concepts

  8. CPU Switch From Process to Process Operating System Concepts

  9. Ready Queue And Various I/O Device Queues Operating System Concepts

  10. Representation of Process Scheduling Operating System Concepts

  11. Schedulers • Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue. • Infrequent: seconds or minutes intervals • Controls degree of multi-programming • Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU. • Millisecond intervals • Medium-term scheduler (swapper) Operating System Concepts

  12. Context Switch • When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. • Context-switch time is overhead; the system does no useful work while switching. • Time dependent on hardware support. Operating System Concepts

  13. Process Creation • Parent process creates children processes, which, in turn create other processes, forming a tree of processes. • Resource sharing • Parent and children share all resources. • Children share subset of parent’s resources. • Parent and child share no resources. • Execution • Parent and children execute concurrently. • Parent waits until children terminate. Operating System Concepts

  14. Process Creation (Cont.) • Address space • Child duplicate of parent. • Child has a program loaded into it. • UNIX examples • fork system call creates new process, returns PID • execve system call used after a fork to replace the process’ memory space with a new program. • See sample code if available Operating System Concepts

  15. A Tree of Processes On A Typical UNIX System Operating System Concepts

  16. Process Termination • Process executes last statement and asks the operating system to decide it (exit). • Parent may terminate execution of children processes (abort). • Child has exceeded allocated resources. • Task assigned to child is no longer required. • Parent is exiting. • Etc. • Parent termination may cascade Operating System Concepts

  17. Threads • A thread (or lightweight process) is a basic unit of CPU utilization; it consists of: • program counter • register set • stack space • A thread shares with its peer threads its: • code section • data section • operating-system resources collectively known as a task. • A traditional or heavyweight process is equal to a task with one thread • See process viewer example if available Operating System Concepts

  18. Threads (Cont.) • In a multiple threaded task, while one server thread is blocked and waiting, a second thread in the same task can run. • Cooperation of multiple threads in same job confers higher throughput and improved performance. • Examples: Web servers, Database servers • Allow sequential processes to make blocking system calls while also achieving parallelism. • Kernel-supported threads • User-level threads; supported above the kernel, via a set of library calls • Hybrid approach implements both user-level and kernel-supported threads (Solaris 2). Operating System Concepts

  19. Multiple Threads within a Task Operating System Concepts

  20. Interprocess Communication (IPC) • Mechanism for processes to communicate and to synchronize their actions. • Example: Windows NT Local Procedure Call Facility • Message system – processes communicate with each other without resorting to shared variables. • IPC facility provides two operations: • send(message) to <name> • receive(message) from <name> • See examples if available • Processes need to: • establish a communicationlink between them • exchange messages via send/receive Operating System Concepts

  21. IPC (Cont’d) • Implementation of communication link • Shared memory • hardware bus • Etc. • Direct communication link • Shared memory • Pipes • Sockets • Semaphores • Indirect communication link • Mailboxes Operating System Concepts

  22. Module 5: CPU Scheduling • Basic Concepts • Scheduling Criteria • Scheduling Algorithms • Multiple-Processor Scheduling • Real-Time Scheduling • Algorithm Evaluation Operating System Concepts

  23. Basic Concepts • Maximum CPU utilization obtained with multiprogramming • CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait. • CPU burst distribution Operating System Concepts

  24. Alternating Sequence of CPU And I/O Bursts Operating System Concepts

  25. Histogram of CPU-burst Times Operating System Concepts

  26. CPU Scheduler • Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. • CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state. 2. Switches from running to ready state. 3. Switches from waiting to ready. 4. Terminates. • Scheduling can be nonpreemptive. (ex: Win3x) • Or, preemptive.(ex: Win95+) • A dispatch routine does the actual context switch Operating System Concepts

  27. Scheduling Criteria • CPU utilization – keep the CPU as busy as possible • Throughput – # of processes that complete their execution per time unit • Turnaround time – amount of time to execute a particular process • Waiting time – amount of time a process has been wiating in the ready queue • Response time – amount of time it takes from when a request was submitted until the first response is produced, not output Operating System Concepts

  28. P1 P2 P3 0 24 27 30 First-Come, First-Served (FCFS) Scheduling • Example: ProcessBurst Time P1 24 P2 3 P3 3 • Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: • Waiting time for P1 = 0; P2 = 24; P3 = 27 • Average waiting time: (0 + 24 + 27)/3 = 17 • Turnaround for P2 = 24 + 3 = 27 Operating System Concepts

  29. FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P2 , P3 , P1 . • The Gantt chart for the schedule is: • Waiting time for P1 = 6;P2 = 0; P3 = 3 • Average waiting time: (6 + 0 + 3)/3 = 3 • Much better than previous case. • Convoy effect: short process stack up behind long process P2 P3 P1 0 3 6 30 Operating System Concepts

  30. Shortest-Job-First (SJR) Scheduling • Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time • But: how do we know what the next burst is? (more on this). • Two schemes: • Non preemptive • Preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF). • SJF is optimal – gives minimum average waiting time Operating System Concepts

  31. Example of Non-Preemptive SJF Process Arrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (non-preemptive) • Average waiting time = (w1+w3+w2+w4)/n = (0 + 3 + 6 + 7)/4 = 4 P1 P3 P2 P4 0 3 7 8 12 16 Operating System Concepts

  32. Example of Preemptive SJF Process Arrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (preemptive) • Average waiting time = (9 + 1 + 0 +2)/4 = 3 P1 P2 P3 P2 P4 P1 11 16 0 2 4 5 7 Operating System Concepts

  33. Priority Scheduling • A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority (smallest integer  highest priority). • Preemptive • nonpreemptive • SJF is a priority scheduling where priority is the predicted next CPU burst time. • Problem  Starvation – low priority processes may never execute. • Solution  Aging – as time progresses increase the priority of the process. Operating System Concepts

  34. Round Robin (RR) • Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted. • If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time. Operating System Concepts

  35. P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 Example: RR with Time Quantum = 20 ProcessBurst Time P1 53 P2 17 P3 68 P4 24 • The Gantt chart is: • Typically, higher average turnaround than SJF, but better response time. 0 20 37 57 77 97 117 121 134 154 162 Operating System Concepts

  36. Multilevel Queue Scheduling Operating System Concepts

  37. Multilevel Feedback Queues Operating System Concepts

  38. Multiple-Processor Scheduling • CPU scheduling more complex when multiple CPUs are available. • Homogeneous processors within a multiprocessor. • Load sharing • Asymmetric multiprocessing – only one processor accesses the system data structures, alleviating the need for data sharing. Operating System Concepts

  39. Real-Time Scheduling • Hard real-time systems – required to complete a critical task within a guaranteed amount of time. • Soft real-time computing – requires that critical processes receive priority over less fortunate ones. Operating System Concepts

  40. Group Activity: Processes, Scheduling Operating System Concepts

  41. Module 6: Process Synchronization • Background • The Critical-Section Problem • Synchronization Hardware • Semaphores • Classical Problems of Synchronization • Critical Regions • Monitors • Atomic Transactions Operating System Concepts

  42. Background • Concurrent access to shared data may result in data inconsistency. • Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes. Operating System Concepts

  43. The Critical-Section Problem • n processes all competing to use some shared data • Each process has a code segment, called critical section, in which the shared data is accessed. • Problem – ensure that when one process is executing in its critical section, no other process is allowed to execute in its critical section. • Structure of process Pi repeat entry section critical section exit section remainder section untilfalse; Operating System Concepts

  44. Solution to Critical-Section Problem 1. Mutual Exclusion. If process Pi is executing in its critical section, then no other processes can be executing in their critical sections. 2. Progress. If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely. 3. Bounded Waiting. A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted. Operating System Concepts

  45. Initial Attempts to Solve Problem • Only 2 processes, P0 and P1 • General structure of process • repeat entry section critical section exit section reminder section untilfalse; • Processes may share some common variables to synchronize their actions. Operating System Concepts

  46. Algorithm for 2 Processes • Uses shared variables flag, turn • Initially flag[0] = flag[1] = false; turn can be either 0 or 1 • Process Pi repeat flag [i] := true; /* set pi ready */turn := j; /* set turn to pj */ /* wait while other job is ready and it’s that job’s turn */ while (flag [j] = true and turn = j) dono-op; critical section flag [i] := false; remainder section untilfalse; • Meets all three requirements; solves the critical-section problem for two processes. Operating System Concepts

  47. Synchronization Hardware • Can be used to implement mutual exclusion • Test and modify the content of a word atomically. function Test-and-Set (var target: boolean): boolean; begin Test-and-Set := target;target := true; end; Operating System Concepts

  48. Semaphore • Synchronization tool that does not require busy waiting (spinlocks) - Can use block, wakeup • Semaphore S – integer variable • can only be accessed via two indivisible (atomic) operations wait (S): whileS 0 dono-op;S := S– 1; signal (S): S := S + 1; Operating System Concepts

  49. Two Types of Semaphores • Counting semaphore – integer value can range over an unrestricted domain. • Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement. Operating System Concepts

  50. Classical Problems of Synchronization • Readers and Writers Problem • Dining-Philosophers Problem Operating System Concepts

More Related