2 PROCESS MANAGEMENTThe management of running programs is one of the functions of the Operating System
3 A 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.
4 Processes 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
5 ProcessesIn 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.
6 ProcessesResources are normally allocated to the process when it is createdProcesses may also require initialization data and these are also supplied on creation.
7 Processes 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
8 ProcessesAs 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
9 Processes 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
10 Process ManagementProcess StatesEndedRunningCreatedReadyWaiting
11 Process 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.
12 Process ManagementManaging the queues and the execution of programs is one of the major roles of the O/S.
13 The operating system performs many tasks on processes as they execute Process ManagementThe operating system performs many tasks on processes as they execute
14 Process 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
15 Process 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..
16 Process Management process descriptor in your syllabus The PCB is sometimes called theprocess descriptor in your syllabus
17 Process 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.
18 Process 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
19 Process ManagementThe O/S canResume a process : a suspended process once again regains the attention of the CPU. It’s status therefore becomes running
20 Process 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.
21 Process 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.
22 Process 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
23 Process 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.
24 Process 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.
25 Process 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
26 Process 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.
27 Process 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.
28 Process 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
29 Process 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
30 Process 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.
31 Process 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.
33 Process ManagementThere are times when a process needs the attention of the CPU even though it may not be its time to run yet.
34 Process 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
35 Process 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.
36 Process 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.
37 Process Management Interrupt generated by a running process There are four types of interrupts :Interrupt generated by a running processInput/output interruptExternal interruptRestart interrupt
38 Process Managemente.g. A hardware interrupt is sent by printers to the CPU to tell it when they have finished printing a job
39 Process 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,
40 Process 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.
41 Process 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.
42 Process Management Interrupts can be generated by : Hardware device not working properlyA mouse clickA Keyboard character pressedDrive faultSystem errorPrinting finished
44 Process 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.
45 Process ManagementHoweverwhen several processes are attempting to use a number of resources, it is possible for a situation known as DEADLOCK to occur.
46 Example … 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.
47 While 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.
48 So 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
49 If 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.
50 Classifications 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
51 Classifications 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
52 Classifications 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
54 P.M. Heathcote and S. Langfield Text :A’ Level ComputingByP.M. Heathcote and S. LangfieldPages 284 – 286, 293
55 QUESTIONIn 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