Professional Documents
Culture Documents
What is a Process?
A process is a program in execution. A process in execution needs resources like processing resource, memory and IO resource. Imagine a program written in C my_prog.c. After compilation we get an executable. If we now give a command like ./a.out it becomes a process.
What is a Process 2
A computer can have several process running or active at any given time. In case of multiple users on a system, all users share a common processing resource
Processor Utilization - 1
Now think about the processor utilization. What percentage of time are we engaging the processor? Recall that Von Neumann computing requires a program to reside in main memory to run. Clearly, having just one program would result in gross under utilization of the processor. To enhance utilization, we should try to have more than one ready-to-run program resident in main memory.
Processor Utilization - 2
A processor is the central element in a computer s operation. A computer s throughput depends upon the extent of utilization of its processor. Previous figure shows processor idling for very long periods of time when only one program is executed. Now let us consider two ready-to-run memory resident programs and their execution sequence.
Multi-programming Support in OS - 1
Multi-programming Support in OS - 2
In the figure, When prog_1 is not engaging the processor may be utilized to run another ready-to-run program. Clearly, these two programs can be processed without significantly sacrificing the time required to process either of them.
Multi-programming Support in OS - 3
Disadvantage - Overhead faced while switching the context of use of the processor. Advantage 1. Computer resource utilization is improved. 2 Memory utilization is improved with multiple processes residing in main memory. 3 A system would give maximum throughput when all its components are busy all the time.
Response Time - 1
Consider the following scenario :
The number of ready-to-run programs must be maximized to maximize throughput of processor. These programs could belong to different users.
Response Time - 2
A system with its resources being used by multiple users is called time sharing system. For example, a system with multiple terminals. Also a web server serving multiple clients.
However, such a usage has overheads. Lets see some of the overheads.
Response Time - 3
In case of a switch in the context of the use of the processor, we must know where in the program sequence the program was suspended. In addition, intermediate results stored in registers have to be safely stored in a location before suspension.
Response Time - 4
When a large number of resident user programs compete for the processor resource, the frequency of storage, reloads and wait periods also increase. If overheads are high, users will have to wait longer for their programs to execute =>Response Time of the system becomes longer.
Response Time is the time interval which spans the time from when the last character has been input to the time when the first character of the output appears.
Process States
In all the previous examples, we said A process is in RUN state if is engaging the processor, A process is in WAIT state if it is waiting for IO to be completed In our simplistic model we may think of 5 states: 1. 2. 3. 4. 5. New-process Ready-to-run Running Waiting-for-IO and Exit
A Queuing Model
Data structures are used for process management. OS maintains a queue for all ready-to-run processes. OS may have separate queue for each of the likely events (including completion of IO).
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. 2. 3. 4. Switches from running to waiting state. Switches from running to ready state. Switches from waiting to ready. Terminates.
Dispatcher
Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves:
switching context switching to user mode jumping to the proper location in the user program to restart that program
Dispatch latency time it takes for the dispatcher to stop one process and start another running.
Operating System Concepts
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 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 timesharing environment)
Operating System Concepts
Optimization Criteria
Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time
First-Come, First-Served (FCFS) Scheduling Process Burst 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: P1 P2 P3
0 24 27 30
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 behind long process
SJF is optimal gives minimum average waiting time for a given set of processes.
P3 7 8
P2 12
P4 16
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
Burst Time 53 17 68 24
P4
P1
P3
P3
97 117
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
Operating System Concepts
Scheduling
A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1. At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.
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
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.
Algorithm Evaluation
Deterministic modeling takes a particular predetermined workload and defines the performance of each algorithm for that workload. Queueing models
Threads (1)
Figure 2-6 (a) Three processes each with one thread.
Threads (2)
Figure 2-6 (b) One process with three threads.
Threads (3)
Figure 2-7. The first column lists some items shared by all threads in a process. The second one lists some items private to each thread.
Benefits
Responsiveness Resource Sharing Economy Utilization of MP Architectures
Types of Threads
User level Threads Kernel level Threads
User level threads Faster to create & manage Implemented by a thread lib at the user level Can run on any OS Multithread application cannot take advantage of multiprocessing Support provided at user level called user level thread
Kernel level threads Slower to create & manage OS support directly to kernel threads Specific to the OS Kernel routines themselves can be multithreaded Support may be provided by kernel is called kernel level threads
Multithreading Models
Many-to-One One-to-One Many-to-Many
Many-to-One
Many user-level threads mapped to single kernel thread Examples: Solaris Green Threads GNU Portable Threads
Many-to-One Model
One-to-One
Each user-level thread maps to kernel thread Examples Windows NT/XP/2000 Linux Solaris 9 and later
One-to-one Model
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
Many-to-Many Model
Two-level Model
Similar to M:M, except that it allows a user thread to be bound to kernel thread Examples IRIX HP-UX Tru64 UNIX Solaris 8 and earlier
Two-level Model
(a)
Figure 2-28. (a) Possible scheduling of user-level threads with a 50-msec process quantum and threads that run 5 msec per CPU burst.
(b)