1 / 74

UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process Concepts

UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process Concepts Chapter 4: Multithread Programming Threads Chapter 5: Process Scheduling Scheduling Criteria Algorithms – their evaluation Thread Scheduling Case Studies UNIX / Linux / Windows

prue
Télécharger la présentation

UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process Concepts

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. UNIT II Process Management, Thread Scheduling Chapter 3: Process Concept Process Concepts Chapter 4: Multithread Programming Threads Chapter 5: Process Scheduling Scheduling Criteria Algorithms – their evaluation Thread Scheduling Case Studies UNIX / Linux / Windows University Exam Questions Objective Type Questions Process Management, Thread Scheduling

  2. Process Concepts • Process • Process States • Process Control Block (PCB) • Switch from Process to Process • Process Scheduling Queues • Schedulers • Cooperating Processes • Inter Process Communication (IPC) |<< Process Management, Thread Scheduling

  3. Process • A program in execution. • Process execution must progress in Sequential fashion. • includes: • Program Counter • Stack • Data Section Process Management, Thread Scheduling |<<

  4. Process States As a process executes, it changes state • new: The process is being created • running: Instructions are being executed • waiting: The process is waiting for some event to occur • ready: The process is waiting to be assigned to a processor • terminated: The process has finished execution Process Management, Thread Scheduling |<<

  5. Process Control Block (PCB) Information associated with each process • Process State • Program Counter • CPU Registers • CPU Scheduling information • Memory Management information • Accounting information • I/O Status information Process Management, Thread Scheduling |<<

  6. CPU Switch From Process to Process Process Management, Thread Scheduling |<<

  7. Process Scheduling Queues • Job queue • Set of all processes in the system • Ready queue • Set of all processes residing in main memory, ready and waiting to execute • Device queues • Set of processes waiting for an I/O device • Processes migrate among the various queues Process Management, Thread Scheduling

  8. Ready Queue and Various I/O Device Queues Process Management, Thread Scheduling

  9. Representation of Process Scheduling Process Management, Thread Scheduling |<<

  10. Schedulers • Long-term scheduler (or job scheduler) • Selects which processes should be brought into the ready queue • Short-term scheduler (or CPU scheduler) • Selects which process should be executed next and allocates CPU Process Management, Thread Scheduling

  11. Addition of Medium Term Scheduling Process Management, Thread Scheduling |<<

  12. Cooperating Processes • Independent process • cannot affect or be affected by the execution of another process • Cooperating process • can affect or be affected by the execution of another process • Advantages of process cooperation • Information sharing • Computation Speed-up • Modularity • Convenience Process Management, Thread Scheduling |<<

  13. Interprocess Communication (IPC) • Mechanism for processes to communicate and to synchronize their actions • Message system • Processes communicate with each other without resorting to shared variables • Provides two operations: • send(message) – message size fixed or variable • receive(message) • If P and Q wish to communicate, they need to: • establish a communicationlink between them • exchange messages via send/receive • Implementation of communication link • Physical (e.g., shared memory, hardware bus) • Logical (e.g., logical properties) Process Management, Thread Scheduling |<<

  14. Threads • Threads • Benefits • User Threads • Kernel Threads • Multithreading Models • Threading Issues • Application Threads |<< Process Management, Thread Scheduling

  15. Threads • Light Weight Process (LWP). • Basic unit of CPU utilisation. • Comprises of • Thread ID • Program Counter • Register Set • Stack • Types • User Threads • Kernel Threads OS-5 Threads

  16. Single and Multithreaded Processes Process Management, Thread Scheduling |<<

  17. Benefits • Responsiveness • Resource Sharing • Economy • Utilization of Multi Processor Architectures Process Management, Thread Scheduling |<<

  18. User Threads • Thread management done by user-level threads library • Three primary thread libraries: • POSIX Pthreads • Win32 threads • Java threads Process Management, Thread Scheduling |<<

  19. Kernel Threads • Supported by the Kernel • Examples • Windows XP/2000 • Solaris • Linux • Tru64 UNIX • Mac OS X Process Management, Thread Scheduling |<<

  20. Multithreading Models • Many-to-One Model • One-to-One Model • Many-to-Many Model Process Management, Thread Scheduling |<<

  21. Many-to-One Model • Many user-level threads mapped to single kernel thread • Examples: • Solaris Green Threads • GNU Portable Threads Process Management, Thread Scheduling |<<

  22. One-to-One Model • Each user-level thread maps to kernel thread • Examples • Windows NT/XP/2000 • Linux • Solaris 9 and later Process Management, Thread Scheduling |<<

  23. Many-to-Many Model • Allows many user level threads to be mapped to many kernel threads • Allows the operating system to create a sufficient number of kernel threads • Solaris prior to version 9 • Windows NT/2000 with the ThreadFiber package Process Management, Thread Scheduling

  24. Two-Level Model • Similar to Many-to-Many, except that it allows a user thread to be bound to kernel thread. • Examples • IRIX • HP-UX • Tru64 UNIX • Solaris 8 and earlier Process Management, Thread Scheduling |<<

  25. Threading Issues • Semantics of fork() and exec() system calls • Thread Cancellation • Signal Handling • Thread Pools • Thread Specific Data • Scheduler Activations Process Management, Thread Scheduling |<<

  26. Thread Cancellation • Terminating a thread before it has finished. • General approaches: • Asynchronous cancellation • Terminates the target thread immediately • Deferred cancellation • Allows the target thread to periodically check, if it should be cancelled Process Management, Thread Scheduling |<<

  27. Signal Handling • Signals are used in UNIX systems to notify a process that a particular event has occurred • A signal handler is used to process signals • Signal is generated by particular event • Signal is delivered to a process • Signal is handled • Options: • Deliver the signal to the thread to which the signal applies • Deliver the signal to every thread in the process • Deliver the signal to certain threads in the process • Assign a specific thread to receive all signals for the process Process Management, Thread Scheduling |<<

  28. Thread Pools • Create a no. of threads in a pool where they await work • Advantages: • Usually slightly faster to service a request with an existing thread than create a new thread • Allows the no. of threads in the application(s) to be bound to the size of the pool Process Management, Thread Scheduling |<<

  29. Thread Specific Data • Allows each thread to have its own copy of data • Useful when you do not have control over the thread creation process (i.e., when using a thread pool) Process Management, Thread Scheduling |<<

  30. Scheduler Activations • Both Many-to-Many and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application • Scheduler activations provide upcalls • A communication mechanism from the kernel to the thread library • This communication allows an application to maintain the correct number kernel threads Process Management, Thread Scheduling |<<

  31. Application Threads • Pthreads • Windows XP Threads • Linux Threads • Java Threads Process Management, Thread Scheduling |<<

  32. Pthreads • A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization • API specifies behavior of the thread library, implementation is up to development of the library • Common in UNIX operating systems • Solaris • Linux • Mac OS X Process Management, Thread Scheduling |<<

  33. Windows XP Threads • Implements the one-to-one mapping • Each thread contains • A thread id • Register set • Separate user and kernel stacks • Private data storage area • The register set, stacks, and private storage area are known as the context of the threads • The primary data structures of a thread include: • ETHREAD (executive thread block) • KTHREAD (kernel thread block) • TEB (thread environment block) Process Management, Thread Scheduling |<<

  34. Linux Threads • Linux refers to them as tasks rather than threads • Thread creation is done through clone() system call • clone() • allows a child task to share the address space of the parent task Process Management, Thread Scheduling |<<

  35. Java Threads • Java threads are managed by the JVM • Java threads may be created by: • Extending Thread class • Implementing the Runnable interface Java Thread States Process Management, Thread Scheduling |<<

  36. 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 (Non-Preemptive) 2. Switches from running to ready state (Preemptive) 3. Switches from waiting to ready (Preemptive) 4. Terminates (Non-Preemptive) Process Management, Thread Scheduling

  37. Scheduling Criteria • CPU utilization • Keep the CPU as busy as possible • Throughput • No. 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 waiting 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 (for time-sharing environment) Process Management, Thread Scheduling

  38. Optimization Criteria • Max CPU utilization • Max throughput • Min turnaround time • Min waiting time • Min response time |<< Process Management, Thread Scheduling

  39. Scheduling Algorithms • FCFS Scheduling • SJF Scheduling • Non-Preemptive • Preemptive • Priority Scheduling • Round Robin • Multilevel Queue Scheduling • Multilevel Feedback Scheduling |<< Process Management, Thread Scheduling

  40. P1 P2 P3 0 24 27 30 FCFS Scheduling ProcessBurst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 Gantt Chart: Waiting time for P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0 + 24 + 27) / 3 = 17 Process Management, Thread Scheduling

  41. P2 P3 P1 0 3 6 30 FCFS Scheduling (Cont.) ProcessBurst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P2 , P3 , P1 Gantt Chart: Waiting time for P1 = 6;P2 = 0;P3 = 3 Average waiting time: (6 + 0 + 3) / 3 = 3 Process Management, Thread Scheduling |<<

  42. Shortest-Job-First (SJF) Scheduling • Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time • Schemes: • Non-Preemptive • Once CPU given to the process it cannot be preempted until completes its CPU burst • Preemptive / Shortest-Remaining-Time-First (SRTF) • If a new process arrives with CPU burst length less than remaining time of current executing process, preempt. • Optimal • Gives minimum average waiting time for a given set of processes Process Management, Thread Scheduling |<<

  43. P1 P3 P2 P4 0 3 7 8 12 16 Example of Non-Preemptive SJF ProcessArrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 Gantt Chart: Average waiting time = (0 + 6 + 3 + 7) / 4 = 4 Process Management, Thread Scheduling |<<

  44. P1 P2 P3 P2 P4 P1 11 16 0 2 4 5 7 Example of Preemptive SJF ProcessArrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 Gantt Chart: Average waiting time = (9 + 1 + 0 +2) / 4 = 3 Process Management, Thread Scheduling |<<

  45. Priority Scheduling • A priority No. (Integer) is associated with each process • The CPU is allocated to the process with the highest priority • Smallest integer  highest priority • Preemptive • Non-preemptive • 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 Process Management, Thread Scheduling |<<

  46. 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 and added to the end of the ready queue. • 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 in chunks of at most q time units at once. • No process waits more than (n-1)q time units. Process Management, Thread Scheduling

  47. P1 P2 P3 P4 P1 P3 P4 P1 P3 P3 0 20 37 57 77 97 117 121 134 154 162 Example of RR with Time Quantum = 20 ProcessBurst Time P1 53 P2 17 P3 68 P4 24 Gantt chart: Higher average turnaround than SJF, but better response Process Management, Thread Scheduling |<<

  48. Multilevel Queue • Ready queue is partitioned into separate queues: • Foreground (Interactive) • Background (Batch) • Each queue has its own scheduling algorithm • Foreground – RR • Background – FCFS • Scheduling must be done between the queues • Fixed priority scheduling; • (i.e., serve all from foreground then from background). • Possibility of starvation. • Time slice • Each queue gets a certain amount of CPU time which it can schedule amongst its processes; • i.e., 80% to foreground in RR • 20% to background in FCFS Process Management, Thread Scheduling

  49. Multilevel Queue Scheduling Process Management, Thread Scheduling |<<

  50. Multilevel Feedback Queue • A process can move between the various queues; • aging can be implemented this way • Multilevel-feedback-queue scheduler defined by the following parameters: • No. of queues • Scheduling algorithms for each queue • Method used to determine when to upgrade a process • Method used to determine when to demote a process • Method used to determine which queue a process will enter when that process needs service Process Management, Thread Scheduling

More Related