Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Operating Systems Process Management What is a Process? 2 The basic unit of software that the operating system deals with in scheduling the work done by the processor. Not the same as an application, since an application can cause multiple processes to be executed. Can be defined as software that performs some action and can be controlled - by a user, by other applications or by the operating system. What Is A Process A process consists of the machine code image of the program and a Process Control Block (PCB). The PCB typically contains: – – – – – – – – 3 An ID number that identifies the process Pointers to the locations in the program and its data where processing last occurred Register contents States of various flags and switches Pointers to the upper and lower bounds of the memory required for the process A list of files opened by the process The priority of the process The status of all I/O devices needed by the process Listing Processes in UNIX The ps command displays process information in the following format: PID 291 353 – – – – 4 TTY 01 01 TIME 00:02 00:00 COMMAND sh ps PID: process id TTY: id of terminal owning process TIME: cumulative amount of CPU time used COMMAND: command which generated the process. Listing Processes in Windows 5 Right-click on task bar Select Task Manager Applications tab shows running application Processes tab shows running processes and the system resources each is using. Status Bar shows the number of processes running and the CPU utilization. Process Life-Cycle I/O Completion Process Entry Ready Blocked Running 6 Termination Process Life-Cycle READY – – BLOCKED – – process is waiting for an I/O operation to complete and cannot utilise the CPU many processes may be in a BLOCKED state at any instant RUNNING – – 7 process is able to use the CPU when it is assigned to it many processes may be in a READY state at any instant process is using the CPU for a single-CPU computer only one process can be in a RUNNING state at any instant Process Scheduling 8 The CPU can only do one thing at a time. In order to give the appearance of lots of things happening at the same time, the operating system has to switch between different processes thousands of times a second. This function is performed by the process scheduler. Objectives of Scheduling 9 Equity Maximize throughput Be predictable Balance resource use Avoid indefinite postponement Enforce priorities Give preference to processes holding key resources Degrade gracefully under heavy loads Criteria for Scheduling 10 Priority assigned to a process. Class of process – batch, online or real-time. Resource requirements. CPU-bound or I/O bound. Resources used to date. Waiting time to date. Scheduling Policies Preemptive – Non-preemptive – process runs until it terminates or incurs an I/O wait. Cooperative – 11 scheduler may suspend a process in order to allow another process to run. process periodically relinquishes control of the CPU. Scheduling Algorithms First-Come-First-Served (FCFS) – – – – Shortest Job First (SJF) – – – 12 the first process in the READY state gets the CPU non-preemptive long jobs favored over short ones I/O bound processes will be idle for long periods. the process with the shortest estimated run-time gets the CPU non-preemptive long-running processes could be starved for the CPU Scheduling Algorithms Shortest Remaining Time (SRT) – – – Highest Response Ratio Next – – – 13 preemptive version of SJF a process with a shorter estimated run-time than the current process’ remaining run-time will get the CPU. long-running processes could be starved for the CPU non-preemptive a process is assigned a priority based on the time it has spent waiting and its estimated run-time higher priority processes get the CPU first Scheduling Algorithms Round Robin (RR) – – – – Multi-level Feedback Queues (MFQ) – – – 14 preemptive processes get the CPU in FCFS sequence once the process has run for a defined period (time quantum) it is interrupted and the next process gets the CPU no process can “hog” the CPU maintains a number of separate queues, each of which represents a different priority processes in a lower priority queue do not get the CPU unless the higher priority queues are empty each queue uses RR, if a process uses up its time quantum is moves to the end of the queue on the next lower level. Scheduling in UNIX 15 Uses the MFQ algorithm. Processes are assigned an initial priority. The priority is represented by an integer, the higher the integer the lower the priority. Priority is increased the longer the process waits. Priority is reduced the longer the process runs. A process’ initial priority can be adjusted using the nice command. Only a superuser can increase a process’ initial priority. Scheduling in Windows 16 Windows 95 and 98 used a cooperative policy. Windows NT (and later) use a preemptive policy with a round-robin algorithm similar to UNIX. Process priority is represented by six (6) states – realtime, high, abovenormal, normal, belownormal, low. A process’ initial priority can be changed with the START command. Only a superuser can increase a process’ priority. Process Thrashing 17 Process switching happens without direct user interference, and each process gets enough CPU cycles to accomplish its task in a reasonable amount of time. If enough processes are started, and if the operating system hasn't been carefully designed, the system can begin to use the vast majority of its available CPU cycles to swap between processes rather than run processes. This situation is known as thrashing. Interrupt System 18 In addition to executing processes, the CPU must also respond to interrupts. Interrupts are special signals sent by hardware or software to the CPU. Sometimes the operating system will schedule the priority of processes so that interrupts are masked that is, the operating system will ignore the interrupts from some sources so that a particular job can be finished as quickly as possible. Interrupt System 19 There are some interrupts that are so important that they can't be ignored. These non-maskable interrupts (NMIs) must be dealt with immediately. The importance of the interrupt system is that it permits several programs and I/O activities to proceed independently. Types of Interrupts 20 I/O – Generated by the controller of an I/O device, to signal normal completion or the occurrence of an error or failure condition. Timer – Generated by the internal clock, used to alert the operating system at predetermined intervals. Hardware Error – Generated by hardware faults. Program – Generated by error conditions within user programs. Multi-CPU Systems 21 In a system with two or more CPUs, the operating system must divide the workload among the CPUs. Asymmetric operating systems use one CPU for their own needs and divide application processes among the remaining CPUs. Symmetric operating systems divide processes among the various CPUs, balancing demand versus CPU availability even when the operating system itself is all that's running.