2PROCESS MANAGEMENTThe management of running programs is one of the functions of the Operating System
3A program is only regarded as a process when it is being executed. Process ManagementThe basic unit of software that the operating system deals with is … a process.A process is defined as a running program (It exists in memory, is performing some action and can be controlled by a user, an application or the operating system).A program is only regarded as a process when it is being executed.
4Processes may be system processes or application processes Examples of processes are :A game being playedMS Word runningData being transmitted along a networkAntivirus software runningProcesses may be system processes or application processes
5ProcessesIn order for processes to run properly to completion they need computer resources such as :CPU timeMemoryFiles (on secondary storage devices) andI/O devices in order to complete their tasks.
6ProcessesResources are normally allocated to the process when it is createdProcesses may also require initialization data and these are also supplied on creation.
7Processes Processes are created when the program first begins to run. It may be started by the O/S itself, by a utility or by a user/application program
8ProcessesAs a process runs there are several possible states that it may be in depending on what is happening in the process itself, and also in the overall system
9Processes The states are : READY – the process can use the CPU if the CPU is availableRUNNING – The process is being executed by the CPUBLOCKED – The process is waiting for an event to happen before it can continue Otherwise called “waiting”ENDED The process is no longer running
11Process ManagementAny number of processes can be READY at the same time so a READY QUEUE is maintained for all processes hoping to run soon.Only one process at a time can have the status RUNNINGA queue of BLOCKED or WAITING processes is also maintained.
12Process ManagementManaging the queues and the execution of programs is one of the major roles of the O/S.
13The operating system performs many tasks on processes as they execute Process ManagementThe operating system performs many tasks on processes as they execute
14Process ManagementThe O/S canCreate a process : the program is brought into memory (RAM) and given a process control block. Its status is then set to READY
15Process ManagementThe PCB is a small piece of memory that stores information about a running program. Every process has a PCBTypically the PCB stores the following data : the process id, the user name, the time started, the priority, the state, the time elapsed, data registers, etc..
16Process Management process descriptor in your syllabus The PCB is sometimes called theprocess descriptor in your syllabus
17Process ManagementThe O/S canDestroy / Kill a process : this involves terminating a process before it has run to completion.This may be initiated by the user, the application or the system and then performed by the O/S.
18Process ManagementThe O/S canSuspend a process : the process is paused as the CPU’s attention is given to another process. Its status is changed to either WAITING or READY and it goes to the appropriate queue
19Process ManagementThe O/S canResume a process : a suspended process once again regains the attention of the CPU. It’s status therefore becomes running
20Process ManagementThe O/S can :Change a process’ priority : The priority is a rating that determines the process’ position in the ready queue. The priority can be upgraded or downgraded, making the process more important or less important, and thus changing how long a waiting time it has.
21Process ManagementA single CPU can only attend to one process at a time.Yet many O/Ss give the appearance that they can simultaneously run many programs.
22Process ManagementWhen the Operating System executes more than one process concurrently so that they appear to be running at the same time, it is said to be multiprogramming. They are active in memory at the same time but only one is being executed by the CPU
23Process ManagementThe CPU is so fast that it appears that it is doing several things at the same time when in fact it is doing them one after the other in small time slices.
24Process Management Multiprogramming An operating system managing several processes at the same time so it appears as if they all being executed by the CPU at the same time.
25Process Management One way of accomplishing this : The operating system assigns a time slice to every process that it creates in units of CPU cycles.Once it is not interrupted, the process has the attention of the CPU for that number of cycles.The other processes wait in the ready queue
26Process ManagementWhen the time is up the process state is set to ready and stored in the PCB along with the current data. The CPU then moves the process to the back of the ready queue.The CPU next takes the process at the front of the ready queue and begins to work on it. It runs for that time slice and the technique is repeated.
27Process ManagementEventually the earlier process gets another time slice. This is called the round-robin approachThe combination of the small time slice and the speed of the CPU means that it appears that all the processes are running at the same time. This complex operation is managed by the operating system.
28Process Management Shortest job first (SJF) The O/S uses one of the following techniques called Scheduling Algorithms to decide which program will run next.Shortest job first (SJF)Shortest remaining time first (SRTF)These are called pre-emptive algorithmsBased on a characteristic of the process
29Process Management 4. First come first serve (FCFS) Scheduling Algorithms cont’d4. First come first serve (FCFS)Priority schedulingRound robinThese are called non-pre-emptive algorithms
30Process Management . Note : the O/S aims to do the following : Process the maximum number of jobsBe as fair to each user as possibleProvide acceptable response times to online usersKeep the devices busyAvoid deadlockDegrade gracefully, instead of freezing, if the system is overloaded.
31Process ManagementOften an operating system uses a combination of strategies.ExampleShortest job first may be combined with priority scheduling. After all, if two or more jobs have the same priority some other mechanism must be used to decide which gets executed first.
33Process ManagementThere are times when a process needs the attention of the CPU even though it may not be its time to run yet.
34Process ManagementExternal operations such as getting data from the disk or printing (I/O operations) are much, much slower than the CPU.So instead of waiting for these operations to complete, the O/S will block that process (set it to waiting) and send another one which is ready to the CPU
35Process ManagementE.g.when a process needs data or is printing. When the print starts the CPU sends the request to the device driver and the O/S moves the process into the waiting queue.
36Process ManagementWhen the I/O operation is complete the waiting process generates an INTERRUPT to the O/S.An interrupt is a special signal sent by the hardware or the software to gain the CPU’s attention.
37Process Management Interrupt generated by a running process There are four types of interrupts :Interrupt generated by a running processInput/output interruptExternal interruptRestart interrupt
38Process Managemente.g. A hardware interrupt is sent by printers to the CPU to tell it when they have finished printing a job
39Process ManagementThe CPU will then respond by completing the step it is on, pausing what it was doing and storing the data for the current process in its PCB,
40Process ManagementIt will then check to see the type of interrupt, go to the interrupt routines to determine how to handle this particular interrupt, and then execute the interrupt routine.When it is finished handling the interrupt it puts the job in the ready queue and then return to the original process.
41Process ManagementWhile this sounds like a long process, it is usually done in a few millionths of a second so that the user does not even know that it has happened.Sometimes there can be scores of interrupts per second.
42Process Management Interrupts can be generated by : Hardware device not working properlyA mouse clickA Keyboard character pressedDrive faultSystem errorPrinting finished
44Process Management LOCKS When a process is using a resource it locks it, so that there can be no conflict in use.This prevents lots of possible errors e.g. two users trying to change the same data at the same time.
45Process ManagementHoweverwhen several processes are attempting to use a number of resources, it is possible for a situation known as DEADLOCK to occur.
46Example … Lets say Process1 opened a file called FileA. It then attempts to use the printer.Process2 is however using the printer so ProcessI has to wait.
47While still using the printer Process2 finds a need to use FileA While still using the printer Process2 finds a need to use FileA. When it attempts to do so it finds that FileA is already in use by Process1.So Process2 goes to the waiting queue to wait on Process1 to free up the file.
48So both are in the waiting queue waiting on each other - This will never happen because Process1 is also in the wait queue waiting on Process2.So both are in the waiting queue waiting on each other -Thus we have DEADLOCK
49If deadlock does occur the O/S is allowed to end a process. Process ManagementTo avoid deadlocks we can take the following steps:Do not allow a process to start until all its resources are availableAlways allocate resources in the same sequence e.g. data then printerIf deadlock does occur the O/S is allowed to end a process.
50Classifications of Operating Systems Single user – an o/s designed to be used by one person at a timeMulti-user - allows several users access concurrently; eg midrange systems such as mainframes where one computer has many users running different programs from multiple attached terminals
51Classifications of Operating Systems Single tasking – an o/s that can only execute one process at a timeMultiprogramming – capable of executing several processes at once by use of a scheduling algorithm for the CPU
52Classifications of Operating Systems Multiprocessing – having more than one processor available for running processesNetwork O/S – runs on a main controlling computer (server) and provides communication and routing services so that clients can share data, programs, etc
54P.M. Heathcote and S. Langfield Text :A’ Level ComputingByP.M. Heathcote and S. LangfieldPages 284 – 286, 293
55QUESTIONIn a batch programming environment, the following 3 programs are ready to run: a payroll program, a complicated scientific calculation and the printing of a long queue of reportsExplain one reason for giving the queue of reports the highest priorityExplain one reason why the scientific calculation should be given the lowest priority