Presentation on theme: "PROCESS MANAGEMENT Y. Colette LeMard. PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System."— Presentation transcript:
PROCESS MANAGEMENT Y. Colette LeMard
PROCESS MANAGEMENT The management of running programs is one of the functions of the Operating System
Process Management The 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.
Processes Examples of processes are : – A game being played – MS Word running – Data being transmitted along a network – Antivirus software running Processes may be system processes or application processes
Processes In order for processes to run properly to completion they need computer resources such as : – CPU time – Memory – Files (on secondary storage devices) and – I/O devices in order to complete their tasks.
Processes Resources are normally allocated to the process when it is created Processes may also require initialization data and these are also supplied on creation.
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
Processes As 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
Processes The states are : READY – the process can use the CPU if the CPU is available RUNNING – The process is being executed by the CPU BLOCKED – The process is waiting for an event to happen before it can continue. Otherwise called waiting ENDED - The process is no longer running
Process Management Process States Ready Waiting Ended Running Created
Process Management Any 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 RUNNING A queue of BLOCKED or WAITING processes is also maintained.
Process Management Managing the queues and the execution of programs is one of the major roles of the O/S.
Process Management The operating system performs many tasks on processes as they execute
Process Management The O/S can 1. - Create a process : the program is brought into memory (RAM) and given a process control block. Its status is then set to READY
Process Management The PCB is a small piece of memory that stores information about a running program. Every process has a PCB Typically 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..
Process Management The PCB is sometimes called the process descriptor in your syllabus
Process Management The O/S can 2. - Destroy / 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.
Process Management The O/S can 3. - Suspend a process : the process is paused as the CPUs attention is given to another process. Its status is changed to either WAITING or READY and it goes to the appropriate queue
Process Management The O/S can 4. - Resume a process : a suspended process once again regains the attention of the CPU. Its status therefore becomes running
Process Management The O/S can : 5. 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.
Process Management A 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.
Process Management When 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
Process Management The 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.
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.
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 Process Management
When 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.
Process Management Eventually the earlier process gets another time slice. This is called the round-robin approach The 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.
Process Management The O/S uses one of the following techniques called Scheduling Algorithms to decide which program will run next. 1. Shortest job first (SJF) 2. Shortest remaining time first (SRTF) These are called pre-emptive algorithms
Process Management Scheduling Algorithms contd 4.First come first serve (FCFS) 5. Priority scheduling 6. Round robin These are called non-pre-emptive algorithms
Process Management. Note : the O/S aims to do the following : – Process the maximum number of jobs – Be as fair to each user as possible – Provide acceptable response times to online users – Keep the devices busy – Avoid deadlock – Degrade gracefully, instead of freezing, if the system is overloaded.
Process Management Often an operating system uses a combination of strategies. Example Shortest 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.
Process Management Questions ?
Process Management There are times when a process needs the attention of the CPU even though it may not be its time to run yet.
Process Management External 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
Process Management E.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.
Process Management When 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 CPUs attention.
Process Management There are four types of interrupts : – Interrupt generated by a running process – Input/output interrupt – External interrupt – Restart interrupt
Process Management e.g. A hardware interrupt is sent by printers to the CPU to tell it when they have finished printing a job
Process Management The 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,
Process Management It 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.
Process Management While 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.
Process Management Interrupts can be generated by : – Hardware device not working properly – A mouse click – A Keyboard character pressed – Drive fault – System error – Printing finished
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.
Process Management However when several processes are attempting to use a number of resources, it is possible for a situation known as DEADLOCK to occur.
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.
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.
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
Process Management To avoid deadlocks we can take the following steps: Do not allow a process to start until all its resources are available Always allocate resources in the same sequence e.g. data then printer If deadlock does occur the O/S is allowed to end a process.
Classifications of Operating Systems Single user – an o/s designed to be used by one person at a time Multi-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
Classifications of Operating Systems Single tasking – an o/s that can only execute one process at a time Multiprogramming – capable of executing several processes at once by use of a scheduling algorithm for the CPU
Classifications of Operating Systems Multiprocessing – having more than one processor available for running processes Network O/S – runs on a main controlling computer (server) and provides communication and routing services so that clients can share data, programs, etc
A Level Computing By P.M. Heathcote and S. Langfield Pages 284 – 286, 293 Text :
QUESTION In 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 reports i. Explain one reason for giving the queue of reports the highest priority ii. Explain one reason why the scientific calculation should be given the lowest priority