Dr. Andrea Bracciali, Room 4B86,

Size: px
Start display at page:

Download "Dr. Andrea Bracciali, Room 4B86,"

Transcription

1 Operating Systems Dr. Andrea Bracciali, Room 4B86, 1 Operating systems 1. Basic concepts 2. History 3. Modern OS as virtual machines 4. File manager and peripherals manager 5. Protection 6. Resource management: 1. Memory manager 2. Processes and multitasking [CPU - and other resources] 3. Scheduling [CPU - and other resources] 4. Deadlocks [Computation in general] 1.2 1

2 Operating Systems: Introduction Running an application (informal description): Via an interface, typically a windows/icon interface, you can select and launch an application by double-clicking its icon with the mouse. You double click on the icon of your voip preferred program. The executable code of the application is loaded from an hard disk into the RAM memory and the processor starts to execute it. The disk spins, after a while the windows of the program opens. Possibly, the application interacts with one or more users and other devices, and uses available resources. You select one of your contact and start a call, the built-in camera starts to record images that the app processes and broadcasts together with voice. At a certain point you decide to send a file to the contact, who in turn sends back a picture. It may happen that several application run concurrently sharing data and computational power, i.e. the processor [although you may not realise it]. You decide to save the received picture, open it, and print it. In doing so, a photo application is launched, and it accesses the printer. How does all this happen? 1.3 Operating Systems: Introduction Running an application (informal description): Video/mouse/keyboard interface File system You double click on the icon of your voip preferred program. Device management: Disk, Drivers, Bus, Memory, Processor. The disk spins, after a while the windows of the program opens. Running the code Running several processes (i.e. programs, for the time being), safely Managing resources Reacting to several events You select one of your contact and start a call, the built-in camera starts to record images that the app processes and broadcasts together with voice. At a certain point you decide to send a file to the contact, who in turn sends back a picture. Managing processes, processor(s) and memory allocation, inter-process and external communications You decide to save the received picture, open it, and print it. In doing so, a photo application is launched, and it accesses the printer

3 Operating Systems: Introduction An Operating System (OS) is in charge of most of the mentioned tasks! It is a large and complex application itself, perhaps with special capabilities, that manages the computer and provide an high-level access to the computer itself. It manages the internal functionalities of a computer, such as processor allocation to processes, as well as interface functionalities with local and remote structures and devices, such as file systems, disks or network communications. The OS is continuously executing (concurrently with other other applications) whenever the computer is on. Generally, it may be composed of several, possibly layered, components. Unix, Well known OS are MS Dos Linux, MacOS, MS Windows Android ios 1.5 A bit of history 1.6 3

4 Managing programs on early computers On early computers, programs were all in machine code and ran directly on the computer, with no interface. Input was from switches, paper tape, cards, tape, etc and output was in lights, print, paper tape, cards, etc. High level languages (like ForTran) made programming easier, but running programs became a complicated task. To run a ForTran program, each programmer had to: load the ForTran compiler (perhaps from tape) load the program (perhaps from punched cards) compile the program and save it (on another tape) load the compiled program load the program s data (perhaps from punched cards) run the program and save or print its output 1.7 Console of the Ferranti Mark

5 Managing programs on early computers This long list of tasks increased setup time and reduced utilisation (the proportion of time the computer is actually being used) and programmer productivity. Initial solution: employ a (human) computer operator to perform the tasks of loading and running programs, thus freeing the programmers to get on with writing and debugging their programs. The computer operator s job was mindless and mechanical so, a small program was developed to do automatic job sequencing, replacing the human operator. This program was called the monitor. 1.9 Managing programs with a monitor The monitor program was loaded when the computer was switched on, and then kept permanently in main memory (unlike user programs). The sequence of events was now as follows: Turn on the computer Load the monitor Run the monitor: The monitor reads and interprets a punched card describing the next job (a user program, plus its associated data) to be run. It loads this job from punched cards into memory. It then passes control to the job. The job executes, and (ideally) then returns control to the monitor, and the cycle begins again

6 Problems with the monitor system There was no protection from errors in user programs: the running program had access to all of main memory, and could corrupt the monitor a program could accidentally read too many data cards, affecting the next job a program could enter an infinite loop, making the computer unusable. (There was no way of interacting with, or interrupting the currently running program, other than switching off the computer.) only one user job could be run at a time: resources were used inefficiently. For example, an I/O bound job (e.g., printing a file) would prevent other jobs from using the CPU even though its own CPU use was minimal Modern OS

7 Modern operating systems In modern computers, these problems are solved by a collection of systems programs, which are part of the operating system. The OS, provides, in effect, a virtual machine which is more powerful/efficient/ accessible/... than the machine provided by the hardware The OS virtual machine can provide protection run several programs at the same time (multitasking) provide virtual memory provide programmers with a high-level interface manage access to the machine s resources Components of an operating system Many modern operating systems are constructed in a layered fashion. The outer layer is the user interface (or shell). This is often presented as a graphical user interface, managed by a program called a window manager. It also may contain a set of utility programs (which may modularly be embedded into the OS). The inner layer (or kernel) consists of several components which provide the basic functions of the operating system. These generally regard the managing of the computer architecture and may include: the file manager device drivers the scheduler and dispatcher the memory manager We shall learn about the roles of these components

8 Evolution of Computer Systems User Application Software Operating System Hardware virtual Machine User Operating System Hardware User n... virtual Machine 1.15 Bootstrap programs How does all start? Hardware alone (the raw machine or naked iron ) can do very little. Even the most basic computer needs a built-in program to organise the machine s activity when it is turned on (e.g. to load the first user program and start it running). This program is called the bootstrap (as the machine pulls itself up by its own boot straps ) The bootstrap lives in ROM so that it is present when the computer is switched on. The CPU runs the bootstrap which reads in the Operating System from mass storage (see later). It is relatively small (a few Kb on a PC). It is an example of a system program

9 OS: The interface Different OSs use different means as an interface. For instance, the first versions of UNIX operating system were mainly text-oriented. The system displays a prompt character on the screen to indicate it is waiting for a command. The instructions entered by the user are in the form of a command language. An example command would be: $ ls $ is the prompt char ls provides a list of all files and directories in the current directory 1.17 OS: The interface The interface provided by the Windows OS is a graphical user interface (GUI) To communicate with the user, a GUI supports visual aids, point and click operations entered via a mouse, icons, pull-down menus, scrolling windows and many other visually interactive techniques

10 File manager and device manager 1.19 File management The file manager coordinates the use of the machine s mass storage facilities (e.g. disk, tape, etc) for each file it records the location where it is stored and which users are allowed to access it it keeps track of which areas of mass storage are currently free The OS usually provides the user with a hierarchical view of files organised into directories or folders. Directories may be nested; a chain of directories within directories is called a path eg: C:\IT21\lectures\OS.ppt

11 File management: file protection File protection is provided on an individual file-by-file basis A file may be read or not readable (read protection) A file may be written to or not accessible for writing (write protection) A file may be executed or not be executable (execution protection). So for example, you may have permission to read a file but not write or execute it File management: file protection Example of the Unix OS User base system divided into 3 categories: owner (creator of the file) group (group of users associated with a file) and a universe (rest of the world) Under this protection system, each file provide nine protection flags: read, write, execute for each of the 3 categories

12 Management of peripheral devices As we have seen, communication with peripheral devices (keyboards, displays, etc) is done by means of dedicated hardware controllers. The operating system contains a collection of programs called device drivers. These are the software routines which communicate with the various I/O controllers. The device drivers translate general requests into the technical steps required by a specific device. This allows the design of other programs to be independent of the unique details of particular devices Systems security and protection: users What the users are allowed to do (by the OS)? The OS controls access to the computer and its resources. It has to ensure only authorised users can access the system and ensure that such authorised users are only allowed to do what they are authorised to do! In most OS, access to the computer is via an access control whereby users must enter login id and password before gaining access to the computer. Information about users and passwords is stored in a special file called the password file. Users have hence an identity. File permissions, for instance, allow the OS to dictate what authorised users can do once they are logged on. For example, IT students may have access to particular files on the server to read and write, but they may be prevented to write/update the information in some configuration files. System managers may have access to these files both in read and write mode

13 Systems security and protection: programs What the programs are allowed to do (by the OS)? If application programs were allowed access to all the facilities provided by the (physical) machine, they could cause the computer to crash or corrupt data on its disk(s), including damaging the OS itself. The solution is to prevent such problems by ensuring that access to machine facilities can only be obtained via the OS, that guarantees the proper usage of resources, e.g. a program in execution has a (virtual) area of memory and can not read/write outside it. For example, application programs cannot write data on disk directly. They need to call the specific OS program (in this case, a device driver) which does this job. The OS makes available a set of so-called system calls, by means of which programs can access the computer resources in a controlled manner Systems security and protection: programs How can we ensure that user programs do not circumvent the OS and access the machine facilities directly? A solution: the CPU is built in such a way that it can run programs in at least two modes: supervisor and user modes The supervisor mode has more privileges than user mode, and is used by the OS programs only: application programs are run in the less privileged user mode In each mode the CPU operates by fetching and executing machine instructions (as before) but, for example, access to certain parts of memory is not allowed to instructions executed in user mode. Access is unrestricted to instructions run in supervisor mode

14 How the OS provides protection If a user program attempts to perform an instruction which it is not authorised to do (e.g., access a restricted area of memory), an exception is generated. An exception is a kind of interrupt (we will see later on what an interrupt is. By time being, the interrupt is a message that can stop the "normal" execution of a program). The CPU then stops execution of the user program, and an interrupt handling mechanism is invoked. The interrupt handler in turn invokes the appropriate operating system program to deal with the interrupt How the OS provides protection EXAMPLE: When a user program wishes to write data to disk, the following sequence of actions takes place: The program executes a special instruction, i.e. a system call. This instruction causes a software interrupt to be generated. The execution of the program is suspended (and relevant data about the current state of the computation saved), the CPU is switched to supervisor mode, and the interrupt handler takes over. The interrupt handler invokes the appropriate OS routine for writing to disk. The data is written to disk by an OS routine. The CPU is switched back to user mode and the user program resumes execution

15 Operating systems 1. Basic concepts 2. History 3. Modern OS as virtual machines 4. File manager and peripherals manager 5. Protection 6. Resource management: 1. Processes and multitasking [CPU - and other resources] 2. Scheduling [CPU - and other resources] 3. Deadlocks [Computation in general] 4. Memory manager 1.29 Resource manager: Processes, multitasking and deadlocks

16 Processes The notion of a process is central to operating systems. A process can be thought of as a program in execution, comprising code, data, PC, registers, an allocated memory space... (though sometimes an executing program can spawn other processes, so this is not entirely accurate). Number of processes >> number of CPUs => Some processes cannot run furthermore, some "running" processes might be waiting for something to occur, wasting CPU time, i.e. they might temporarily not need the CPU, which can be assigned to another process Processes That is: Some processes are actually running (as many as the number of CPUs in the computer) others, ready to run, can be waiting for the CPU other processes may be blocked (or suspended) waiting for other resources or events, e.g. the swapping of a page from disk to RAM, as seen

17 Multitasking The OS virtual machine can (in effect) run several programs at the "same" time. Efficient usage of CPU: I/O bound process (editor): CPU bound process (sci calc.): key pressed start Efficient sharing of CPU: overhead 1.33 Multitasking Several application programs (as well as the OS programs) will be stored in memory, but only one program, i.e. a process, is running at any time (on a given CPU). Such a process is called the running process. When certain conditions arise, the currently running process can be temporarily suspended and another started. We say that the CPU is being switched between processes. The CPU can be switched hundreds of times per second, and give the illusion that many programs are being executed at the same time. Other applications/motivations: processes that share information real-time interactivity

18 Multitasking When a process is suspended, its relevant information has to be saved. The operating system stores information about each process (unique id number, resource allocations, etc.) in a process control block (PCB). Hardware Context Software Context Process Control Block Text Process state Program counter CPU scheduling information Memory management inf. Accounting information I/O status information Data Image Process Structure 1.35 Multitasking new process are created (a program is launched) and put in the ready queue (list) then the use of the CPU is assigned to a ready process, which becomes running a running process can either terminate, suspend while waiting for some event to occur or be forced to release the CPU (interrupted), for instance because it is being running for too long or because the OS has to load a new page in memory, and hence be put back to the ready queue a waiting process can eventually become ready again, when the event it was waiting for occurs

19 Multitasking The OS switches CPU between processes according to the occurrence of certain events. These events are signalled by interrupts, i.e. special signals that are sent to the CPU. Modern computers are interrupt driven. There different kinds of interrupt signals: Hardware interrupts are sent by hardware devices such as the I/O device controllers, the system clock or the memory management unit (as seen). Software interrupts are sent by the currently running program (ie, the program can interrupt itself!). These can be triggered by errors (eg division by zero, invalid memory access) or requests for a service provided by the OS (more later) Multitasking At any point in time, each interrupt can be disabled (meaning that the CPU has been instructed to ignore it) or enabled. When an enabled interrupt signal is received, the CPU stops execution of the current program and starts executing an operating system program called the interrupt handler. What this does depends on the nature of the interrupt that was received. Modern operating systems have specific handlers, i.e. pieces of code, for different kinds of interrupts, and use an interrupt vector table to quickly look up the appropriate handler when an interrupt is received

20 Multitasking When an appropriate interrupt signal is received by the CPU, the OS makes a context switch: the current values of all the CPU registers (in particular the PC) is saved in the PCB the PC and other relevant registers are given different values, hence executing a different piece of code. In other words, the current process is suspended and another process started. This may happen because the process is forced to release the CPU, for instance by a timer interrupt, or because the process suspends itself waiting for some event to occur. Since the interrupted process's PC (and other registers), i.e. the process state was saved, it can be continued again at a later time Multitasking Example: The running process A makes an I/O request, by calling the right OS program (!), eg. A is waiting for some data input from the user the OS then passes on the request to the appropriate I/O controller, and enables an interrupt from the device involved (the keyboard controller, in our example) the OS saves A's state the OS switches the CPU to B B is now running when the keyboard controller generates an interrupt, B will be interrupted and control passed back to the OS the OS saves B's state, restores the state of A, disables further interrupts from A's peripheral, makes A running again (by restoring the saved PC). Note that after the second step the I/O controller is handling the I/O operation request issued by A, so that the CPU can be assigned to other tasks, i.e., in our example, running B. Problem: who is B?

21 Operating systems 1. Basic concepts 2. History 3. Modern OS as virtual machines 4. File manager and peripherals manager 5. Protection 6. Resource management: 1. Processes and multitasking [CPU - and other resources] 2. Scheduling [CPU - and other resources] 3. Deadlocks [Computation in general] 4. Memory manager 1.41 Scheduling

22 Scheduling In order to maximise CPU usage, avoid busy wait and support multi-tasking the CPU is switched between processes. Processes are orgainised in ready, running, waiting, and others queues: The scheduler is the component of the OS responsible to select the next ready program to run. The dispatcher is the component of the OS responsible to manage the context switch Scheduler Selects the new ready process to execute. Consists of system calls executed in protected [monitor,supervisor] mode, these are invoked within the context of the the running process. The schedule maintains data in a suitable structure, a queue data structure typically containing process PCBs, e.g:

23 Scheduler When is the scheduler activated? 1. One process switches from running to waiting state 2. One process switches from running to ready state 3. One process switches from waiting to ready 4. One process terminates NOTE: 1,4 is non-preemptive, i.e. the process "decides" to release the CPU, while 2,3 is preemptive, i.e. the running process is "forced" to release the CPU Scheduler Why (for what purpose) is the scheduling mechanism activated? CPU use: maximise CPU usage, this is one of the most important motivations Throughput: maximise the number of completed processes per time unit Turnaround time: (of a process) minimise the time due for completion [waiting+executing+i/o] Waiting time: (of a process) minimise the time spent in the ready queue Response time: (of a process) minimise the time to the first output, e.g., for time-sharing environments. Different goals, e.g.: Minimise the maximum response time for good service to all users Minimise the waiting time for interactive applications

24 Scheduler Different scheduling algorithms exist, exhibiting different features: First Come First Served Shortest Job First Highest Priority First Round Robin (Time Slicing) 1.47 First come-first served (FCFS) Processes are executed in the same order as they become ready. The ready queue is a FIFO queue: an incoming process is inserted in the queue tail, a next-to-execute process is selected from the queue head. Non-preemptive: CPU released only on termination or I/O! Example: Ready queue [ P 3 [3], P 2 [3], P 1 [24]]: Average waiting time: / 3 = 17 0 P 1 P 2 P Ready queue [ P 1 [24], P 3 [3], P 2 [3]]: Average waiting time: / 3 = 3 Convoy effects: all waiting for the "slowest" 0 P 2 P 3 P FCFS: + simple/efficient implementation - poor control over process scheduling [sensitive to arrival order] - bad for interactive [real-time] applications

25 Shortest Job First (SJF) - Each ready process has associated the next CPU time requirement. - The process with the shortest next time process is selected. - The ready queue is a priority queue with predicted next time as a priority. Example: (each line represents the arrival in the ready queue -initial point- and the CPU time requirement - length) P4 P3 P2 P Non-preemptive: (A running process releases the CPU only on termination) Average waiting time: / 4 = 4 0 P 1 P 3 P 2 P Preemptive: Shortest-Remaining-Time-First (SRTF) (A running process releases the CPU on termination or after a given time interval. Note P 4 that has become the shortest one). Average waiting time: / 4 = 3 P 1 P 2 P 3 P 2 P 4 P Shortest Job First (SJF) SJF: + minimizes average waiting time - next CPU time has to be estimated [e.g., weighted average on the most recent running time]

26 Priority scheduling Scheduling can be based on other priorities associated to processes, such as time limits, resource usage, price paid,.... The process with the highest priority is selected. The ready queue is a priority queue. Can be either preemptive or non-preemptive. Same general functioning as SJF (which is an example of priority scheduling). Problem: starvation (common to priority scheduling algorithms) lowest-priority processes indefinitely delayed by incoming highest-priority ones Solution: aging (as seen in page replacement algorithms for memory management) priority of ready processes increases in time so that those "starving", ie., the lowest priority processes indefinitely delayed, age more rapidly than those more frequently running. Priority, then, also depends on age: "too old" starving processes acquire highest priority Round Robin (RR) Based on time slicing: equally shares CPU amongst ready processes: each ready process gets r time units, a time quantum (milliseconds). Different policies are possible for the ready queue (e.g. priority based on process relevance or elapsed CPU time), let us assume FIFO. Preemptive: when quantum expires, the running process is preempted by a clock interrupt. Example: Process in the ready queue are [ P 4 [24], P 3 [68], P 2 [17], P 1 [53] ] and r = 20. P 1 P 2 P 3 P 4 P 1 P 3 P 4 P 1 P 3 P With a ready queue with n processes, the CPU time is equally shared ( 1/n of the total amount) amongst processes and each process waits at most (n-1) r in the queue before getting the CPU (plus context switch overhead!). Relevance of r: r large approximates FCFS, r too small makes context switch overhead predominant RR: + better response time - higher average turnaround time than SJF, typically (depends on time quantum)

27 Dispatcher Once that a new process to run has been selected by the scheduler, the dispatcher, an OS component, is responsible for managing the context switch. It gives control of the CPU to the process selected by the scheduler First, it saves the state of the old process, then loads the state of the new process and jumps to the proper location to resume the new process by suitably setting the PC. Time spent for context switching is critical (dispatch latency)! 1.53 Context Switching

28 Operating systems 1. Basic concepts 2. History 3. Modern OS as virtual machines 4. File manager and peripherals manager 5. Protection 6. Resource management: 1. Processes and multitasking [CPU - and other resources] 2. Scheduling [CPU - and other resources] 3. Deadlocks [Computation in general] 4. Memory manager 1.55 Deadlock

29 OS: Safe use of resources The OS must prevent programs or users from attempting operations that could cause the computer system to enter a state where it is incapable of doing any further work. When resources are involved and required by different programs, it is easy to see how a situation may arise where the computation cannot proceed, and the computer freezes up. This is known as deadlock. The control of access to resources is one of the most important jobs of the OS. By resources we mean here things like: memory space, peripheral devices (disks, printers, display, etc), CPU time, We have discussed some aspects of how an OS manages resources (CPU scheduling and multi-tasking, virtual memory management). We shall now look at issues regarding resource management for deadlock avoidance Deadlock Deadlock, informally speaking, occurs when one or more processes are suspended waiting for a set of events that cannot occur, given the current state of the computer, and will not occur in the future. Deadlock typically involves two or more processes, each of which is waiting for a resource held by one of the other processes. Example: process A has exclusive access to the printer, but requires access to file_1 in order to proceed process B has exclusive access to file_1, but requires access to the printer in order to proceed neither of the two is programmed so as to release any resource until it has accomplished its task. In this example, both processes are blocked from progressing and will remain so indefinitely

30 Deadlock Deadlock may potentially arise in a system which has the following four characteristics: Mutual exclusion: processes compete for resources which cannot be shared. Hold and wait: processes hold resources already allocated to them while waiting for additional resources. No Preemption: once a resource has been allocated to a process, it cannot be forcibly taken away. Circular Wait: must be a circular chain of 2 or more processes. Each is waiting for resources held by the other members of the chain. All the above 4 conditions need to be meet for deadlocks to occur Graphical representation of Deadlock Graphs have two kind of nodes: processes and resources An arc from a resource to a process means the resource has previously been assigned (a) And arc from a process to a resource means the process is requesting this resource (and it is currently blocked on this wait) (b) A circle means deadlock (c)

31 Deadlock The problem of deadlock can be dealt with by several different techniques: 1. Ostrich algorithm: ignore the problem. Maybe if you ignore it, it will ignore you. 2. Prevention: by negating one of the four conditions necessary for deadlocks to occur "BEFORE". 3. Dynamic avoidance: by careful resource allocation "MEANWHILE". 4. Detection and recovery: allow deadlocks to occur, detect them, and take some action "AFTER" Deadlock handling: Deadlock handling: summary 1. Ostrich algorithm: do nothing. 2. Prevention: 1. Mutual Exclusion 2. Hold and Wait 3. No Preemption 4. Circular Wait 3. Dynamic avoidance: safe/unsafe states Banker algorithm. 4. Detection and recovery: 1. Detection 2. Preemption 3. Rollback 4. Killing processes

32 1. Ostrich Algorithm Pretend there is no problem Mathematicians vs engineers Reasonable if deadlocks occur very rarely cost of prevention is high non-critical systems This approach has been traditionally followed by several OSs, some deadlock management components are being added more recently. It is a trade-off between convenience correctness Deadlock prevention Prevention considers the four conditions for deadlock and attacks them Attacking the Mutual Exclusion condition Attacking the Hold and Wait condition Attacking the No Preemption condition Attacking the Circular Wait condition

33 2.1. Attacking Mutual Exclusion The first condition necessary for deadlock is mutual exclusion: resources are not shareable. Sometimes resources have to be assigned to process in a mutually exclusive way. E.g., consider two processes writing to the same printer at the same time. Some devices (such as printer) can be spooled: only the printer server uses the printer resource when a process requests the printer, it is instead connected to a print server process which stores the file to be printed on disk it does this simultaneously for many processes when the (actual) printer becomes available, the OS, via the print server, will take charge of printing the stored files sequentially. This eliminates deadlock for printer usage, because only a process accesses the resource, which hence does not have to be mutually shared anymore Attacking Hold and Wait A process can hold some resources while waiting for others to be allocated to them. Hold and Wait can be attacked by requiring processes to request all the resources before starting execution All resources are assigned at the beginning A process never has to wait for what it needs Processes always run to completion. Problems: Processes may not know required resources at start of run Resources that other processes could be using are tied up Not optimal use of resources! Variation: Processes must give up all resources before acquiring any new one Then, they can request all the immediately-needed resources again

34 2.3. Attacking No Preemption Not very promising! Some resources can not be easily preempted. Imagine a process accessing a CD writer and starting burning the CD, halfway through its job the process is forced to release the CD writer Attacking Circular Wait Several ways of attacking possible: A process is only entitled to a single resource: If a second resource is needed, the first resource has to be freed Imagine a process copying a big file from tape to printer unacceptable! Global numbering of all resources Processes can request resources whenever they want Processes may hold as many resources as needed BUT requests must be made in numerical order

35 2.4. Attacking Circular Wait Each process acquires resources in ascending order The process holding the resource with the highest number associated cannot be waiting for any other resource (before freeing the ones currently held), hence that process can not be part of a circular wait. More in general, there cannot be cycles in the resource graphs, hence no deadlock can occur. Processes will eventually finish, hence freeing their resources Deadlock Dynamic Avoidance It is based on dynamically managing resource allocation. Resources are requested one at a time To avoid deadlocks, the OS must decide whether it is safe or not to allocate a resource and only allocate if its safe Is there a algorithm that can avoid deadlock by making the right choice? Yes but certain information needs to be available The algorithm is based on safe and un-safe states

36 Safe and unsafe states The algorithm relies on the following hypothesis: The maximum number of resources each process needs is known. At any instant the resource availability in the system is known. After a process has obtained all the needed resources it terminates, releasing all the obtained resources. A state is safe if it is not deadlocked, and there exists a possible sequence of resource allocations that allows each process to acquire all the needed resources, according to their maximum limits, and hence to terminate. An unsafe state is not a deadlocked state! but it is a state that will eventually lead to a deadlock if no resources are freed! 1.71 Example (sketch): 3. Deadlock Dynamic Avoidance (cntd.) Processes D and C need resources U and T 2. T is granted to D, the state is safe (as we will see in a minute) 3. U cannot be granted to C, as the resulting state would not be safe, actually it is deadlocked

37 Example (sketch): 3. Deadlock Dynamic Avoidance (cntd.) Processes D and C need resources U and T 2. T is granted to D, the state is safe (as we will see in a minute) 3. U cannot be granted to C, as the resulting state would not be safe, actually it is deadlocked and indeed U is also granted to D 4. D has acquired all the needed resources and it will eventually release them, which then become available to C Deadlock Dynamic Avoidance (cntd.) Safe state: it is guaranteed that all processes will terminate Unsafe state: it cannot be guaranteed that all processes will terminate. One deadlock avoidance algorithm is the Banker s algorithm [Dijkstra] : it relies on safe and unsafe states it denies or delays any resource request that leads the system to an unsafe state when a process has obtained all the resources it needs, it must eventually free them Disadvantages: the maximum amount of resources needed by processes can hardly be known in advance, making the algorithm non feasible the number of processes may vary dynamically, causing new and unforeseen resource needs there are no guarantees on when resources will be released

38 4. Deadlock Detection and Recovery Detection: Construct a resource graph as discussed before If the graph contains any cycles deadlock Any process part in a cycle is deadlocked Algorithms for cycle detection in directed graph have a polynomial complexity. Simplest case: a system has only one resource of each type (1 printer, 1 plotter), but resources with multiplicity are treated analogously Deadlock Detection and Recovery Example with 7 processes and 6 resources Simple to detect deadlocks in a graph However, formal algorithm required for actual implementation much more complex

39 4. Deadlock Detection and Recovery When to check for deadlocks? Every time a resource request has been issued in the system detects deadlocks as early as possible but very costly. Check every n minutes. Check only when the CPU utilisation drops below a certain threshold (only few processes are running) Deadlock Detection and Recovery Recovery: 1. Preemption 2. Rollback 3. Killing processes

40 4. Deadlock Detection and Recovery Recovery through Preemption. Successively take a resource away from a process Assign the resource to another process Depends on resource type, manual intervention may be required Issues: Selection of a victim Order preemption to minimise cost Cost includes: number of resources held, time the process has already run Rollback What to do with the victim? Kill it or rollback to a saved state? Starvation Resources may be preempted from always the same process Processes may be picked only a finite number of times Deadlock Detection and Recovery Recovery through Rollback Checkpoint a process periodically, save state. State should contain memory image and status of resources. Restart the process if it is found deadlocked with the state of the last checkpoint. Work since the used checkpoint is lost. Process has to wait to re-acquire the resources

41 4. Deadlock Detection and Recovery Recovery through Killing Processes Crudest but simplest way to break a deadlock. State of some resources may be incorrect E.g., updating a file Kill all processes in the deadlock Certainly resolves the deadlock Very expensive, all processes need to re-run Kill one process at a time... choose process that can be re-run from the beginning incurs overhead, after a process is aborted the deadlock detection algorithm needs to be run again.... the other processes get the resources of the killed process Deadlock Detection and Recovery Recovery through Killing Processes: Select a process for termination. Several possible criteria! What is the priority of the process? How long has the process computed, and how much longer will the process compute to finish its task? How many and what resources do the processes hold (simple to preempt?)? How many more resources does a process need to complete computation? How many processes will need to be terminated? Is the process interactive or batch?

42 Deadlock handling: Deadlock handling: summary 1. Ostrich algorithm: do nothing. 2. Prevention: 1. Mutual Exclusion 2. Hold and Wait 3. No Preemption 4. Circular Wait 3. Dynamic avoidance: safe/unsafe states Banker algorithm. 4. Detection and recovery: 1. Detection 2. Preemption 3. Rollback 4. Killing processes 1.83 Operating systems 1. Basic concepts 2. History 3. Modern OS as virtual machines 4. File manager and peripherals manager 5. Protection 6. Resource management: 1. Processes and multitasking [CPU - and other resources] 2. Scheduling [CPU - and other resources] 3. Deadlocks [Computation in general] 4. Memory manager

43 Memory manager 1.85 Memory management The memory manager coordinates the machine s use of main memory. The memory manager programs allocate memory space for programs and data, manage allocated memory, and retrieve the allocated space when it is no longer needed. If a machine does only one task at a time, memory management is very simple

44 Memory management Multi-user: computer used by more users at the "same" time Multitasking: several programs/processes running at the "same" time [see later on] Multi-user or multitasking environments make memory management more complicate: Many programs and blocks of data are in memory concurrently, and the memory manager must keep track of all this. In most modern machines, memory management is made even more complex by the provision of virtual memory Virtual memory A running program needs to have its code and data stored in memory, from where they can be accessed. Typically this is the main memory, i.e. the RAM. A program running on a practical computer can usually think about (address) much more memory than what is actually installed on the computer (so programs + data can be larger than available RAM) For example, a program running on a CPU with registers capable of holding 32-bit addresses can access a memory space of 4Gb, but the computer might only have 512Mb, 1Gb or 2Gb of physical memory

45 Virtual memory So apparently CPUs have the addressing capacity to run large programs, and/or run several programs at the same time, but not enough physical memory to do so. We use OS programs and special memory management hardware to remove this discrepancy The (program in execution in the) CPU sees virtual memory instead of physical memory. How? 1.89 Virtual memory Only a part of a program is maintained in the RAM memory, i.e. the part "in use" (RAM fast but expensive and limited). The rest of the program is kept on disk (slower but larger and cheaper). + virtually infinite memory (limited by the disk capacity and addressing capability) + multi-tasking - overhead to manage virtual memory

46 Virtual memory Idea: distinguish between a logical view and a physical view of the memory allocated to a program. The logical view consists of a virtual representation of the program memory, e.g. a contiguous block of memory, possibly larger than the currently available RAM memory. The physical view consists of the actual allocation of the program in memory, e.g. a set of memory blocks, possibly non-contiguous, possibly part in RAM and part in disk. NB: Clearly, this also makes the program "location independent" Virtual memory Logical addresses: represent the locations of bits of code within (the logical view of) a program, but have no real meaning as addresses in the main (physical) memory. Physical addresses: are the actual addresses where programs are located at in main memory. A special hardware/software maps the (logical) addresses used by the CPU to the actual (physical) locations in memory. Whenever the (program running on the) CPU tries to access a part not currently held in memory, the OS transfers the required part from disk to memory, so that the CPU can access it (you can hear this happening)

47 Paging Paging is a method by which virtual memory can be implemented, so that the logical addresses used by a program can be conceptually separated from the address where a program is physically stored in memory. The virtual address space is divided (conceptually) as a number of equalsized blocks: pages The available physical memory is also divided up into sections of the same size: page frames The dimension of the page is chosen so as to optimise performances: a tradeoff between speed/availability (a single large page in RAM, if possible) and the advantages of virtual memory (needs to spread programs between RAM and disk) Paging Paging maintains a correspondence between the logical and physical addresses, such that each logical address is transformed into a physical address when the program is being executed. This transformation is known as mapping (or memory mapping). These operations are handled by the OS and are transparent to the (program running on the) CPU

48 Address calculation (mapping) Memory management hardware (a memory management unit or MMU) converts the virtual addresses issued by the CPU into the physical addresses used to access the (physical) memory. The MMU maintains a page table for each process/program, which for each virtual page, contains a pointer to a page frame (in main memory), or an indication that it is not in main memory. Given a virtual address (by the CPU), the MMU checks if the page is the main memory if it is, computes the corresponding physical address, and handles access to the physical cell of memory Address calculation (mapping) Page Table Entry Format v Page frame number Valid bit Read/Write protection field Valid bit set to 1 if page is resident in physical memory

49 Address calculation (mapping) Virtual Address: Virtual page: 100 Page offset 0 Page Table: (simplified) Page Frame 100 2F Physical Address: Physical page: 2F357 Page offset 1.97 Page swapping If the page is not in memory, a page-fault exception occurs, and an I/O operation is required to transfer pages between physical memory and disk. The current process is blocked until the transfer has been completed [see later on]. The page containing the address in question is swapped in and another page is swapped out to make room. What problem?

50 Page swapping An algorithm chooses the page to be swapped out. Examples of used algorithms are: present for the longest time (First in, First out). least recently used (L.R.U.) least frequently used (L.F.U.) Swapping out only involves actually copying back on to the disk if the page has had its contents changed (because the pages are there on the disk all the time) Page replacement policies First in, First out (FIFO): "pages removed and inserted in the same order" Easy to implement (via a queue) Performs badly in practice Least Recently Used (LRU): "if not used recently will not be needed in the near future" Potentially efficient Difficult to implement Needs to keep track of when the page was last referenced Each page has a counter (kept in page table) Each time a new page is referenced, page counters on other resident pages are incremented (aging) Page with largest counter is swapped out May use hardware counter to assist in this Least Frequently Used (LFU): "if not frequently used not very interesting" Possibly optimal choice Again difficult to implement (needs hardware counter to assist in this)

51 Operating systems 1. Basic concepts 2. History 3. Modern OS as virtual machines 4. File manager and peripherals manager 5. Protection 6. Resource management: 1. Processes and multitasking [CPU - and other resources] 2. Scheduling [CPU - and other resources] 3. Deadlocks [Computation in general] 4. Memory manager

Scheduling. The Basics

Scheduling. The Basics The Basics refers to a set of policies and mechanisms to control the order of work to be performed by a computer system. Of all the resources in a computer system that are scheduled before use, the CPU

More information

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm Evaluation Chapter 5: CPU Scheduling

More information

Deadlocks. Thomas Plagemann. With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

Deadlocks. Thomas Plagemann. With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen Deadlocks Thomas Plagemann With slides from C. Griwodz, K. Li, A. Tanenbaum and M. van Steen Preempting Scheduler Activations Scheduler activations are completely preemptable User" space" Kernel " space"

More information

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5 OPERATING SYSTEMS CS3502 Spring 2018 Processor Scheduling Chapter 5 Goals of Processor Scheduling Scheduling is the sharing of the CPU among the processes in the ready queue The critical activities are:

More information

Chapter 3. Deadlocks

Chapter 3. Deadlocks Chapter 3 Deadlocks 3.1 Resource 3.2 Introduction to deadlocks 3.3 The ostrich algorithm 3.4 Deadlock detection and recovery 3.5 Deadlock avoidance 3.6 Deadlock prevention 3.7 Other issues Resources Examples

More information

DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G

DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G DEADLOCKS M O D E R N O P E R A T I N G S Y S T E M S C H A P T E R 6 S P R I N G 2 0 1 8 NON-RESOURCE DEADLOCKS Possible for two processes to deadlock each is waiting for the other to do some task Can

More information

Unit 3 : Process Management

Unit 3 : Process Management Unit : Process Management Processes are the most widely used units of computation in programming and systems, although object and threads are becoming more prominent in contemporary systems. Process management

More information

Introduction to Computer Science. Polly Huang NTU EE

Introduction to Computer Science. Polly Huang NTU EE Introduction to Computer Science Polly Huang NTU EE http://homepage.ntu.edu.tw/~pollyhuang pollyhuang@ntu.edu.tw Polly Huang, NTU EE Operating System 1 Chapter 3 Operating Systems Polly Huang, NTU EE Operating

More information

Process- Concept &Process Scheduling OPERATING SYSTEMS

Process- Concept &Process Scheduling OPERATING SYSTEMS OPERATING SYSTEMS Prescribed Text Book Operating System Principles, Seventh Edition By Abraham Silberschatz, Peter Baer Galvin and Greg Gagne PROCESS MANAGEMENT Current day computer systems allow multiple

More information

UNIT:2. Process Management

UNIT:2. Process Management 1 UNIT:2 Process Management SYLLABUS 2.1 Process and Process management i. Process model overview ii. Programmers view of process iii. Process states 2.2 Process and Processor Scheduling i Scheduling Criteria

More information

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008. CSC 4103 - Operating Systems Spring 2008 Lecture - XII Midterm Review Tevfik Ko!ar Louisiana State University March 4 th, 2008 1 I/O Structure After I/O starts, control returns to user program only upon

More information

Deadlocks. Today. Next Time. ! Resources & deadlocks! Dealing with deadlocks! Other issues. ! Memory management

Deadlocks. Today. Next Time. ! Resources & deadlocks! Dealing with deadlocks! Other issues. ! Memory management Deadlocks Today! Resources & deadlocks! Dealing with deadlocks! Other issues Next Time! Memory management Introduction to deadlocks A set of threads is deadlocked if each thread in the set is waiting for

More information

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009 CS211: Programming and Operating Systems Lecture 17: Threads and Scheduling Thursday, 05 Nov 2009 CS211 Lecture 17: Threads and Scheduling 1/22 Today 1 Introduction to threads Advantages of threads 2 User

More information

OPERATING SYSTEMS. Deadlocks

OPERATING SYSTEMS. Deadlocks OPERATING SYSTEMS CS3502 Spring 2018 Deadlocks Chapter 7 Resource Allocation and Deallocation When a process needs resources, it will normally follow the sequence: 1. Request a number of instances of one

More information

Chapter 3: Deadlocks

Chapter 3: Deadlocks Chapter 3: Deadlocks Overview Resources Why do deadlocks occur? Dealing with deadlocks Ignoring them: ostrich algorithm Detecting & recovering from deadlock Avoiding deadlock Preventing deadlock Resources

More information

Resources. Lecture 4. Deadlocks. Resources (2) Resources (1) Four Conditions for Deadlock. Introduction to Deadlocks

Resources. Lecture 4. Deadlocks. Resources (2) Resources (1) Four Conditions for Deadlock. Introduction to Deadlocks Lecture 4 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention 3.7. Other issues Resources

More information

Chapter 3. Deadlocks

Chapter 3. Deadlocks Chapter 3 Deadlocks 3.1. Resource 3.2. Introduction to deadlocks 3.3. The ostrich algorithm 3.4. Deadlock detection and recovery 3.5. Deadlock avoidance 3.6. Deadlock prevention 3.7. Other issues Resources

More information

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems Processes CS 475, Spring 2018 Concurrent & Distributed Systems Review: Abstractions 2 Review: Concurrency & Parallelism 4 different things: T1 T2 T3 T4 Concurrency: (1 processor) Time T1 T2 T3 T4 T1 T1

More information

Deadlocks. Today. Next Time. Resources & deadlocks Dealing with deadlocks Other issues. I/O and file systems

Deadlocks. Today. Next Time. Resources & deadlocks Dealing with deadlocks Other issues. I/O and file systems Deadlocks Today Resources & deadlocks Dealing with deadlocks Other issues Next Time I/O and file systems That s some catch, that Catch-22 Thread A: lock(l1); lock(l2);... A Thread B: lock(l2); lock(l1);...

More information

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU BCA-3 rd Semester 030010304-Fundamentals Of Operating Systems Unit: 1 Introduction Short Answer Questions : 1. State two ways of process communication. 2. State any two uses of operating system according

More information

CS450/550 Operating Systems

CS450/550 Operating Systems CS450/550 Operating Systems Lecture 3 Deadlocks Dr. Xiaobo Zhou Department of Computer Science CS450/550 Deadlocks.1 Review: Summary of Chapter 2 Sequential process model Multi-threading: user-space vs.

More information

Ch 4 : CPU scheduling

Ch 4 : CPU scheduling Ch 4 : CPU scheduling It's the basis of multiprogramming operating systems. By switching the CPU among processes, the operating system can make the computer more productive In a single-processor system,

More information

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions: Techno India Batanagar Department of Computer Science & Engineering Model Questions Subject Name: Operating System Multiple Choice Questions: Subject Code: CS603 1) Shell is the exclusive feature of a)

More information

MODERN OPERATING SYSTEMS. Third Edition ANDREW S. TANENBAUM. Chapter 6 Deadlocks

MODERN OPERATING SYSTEMS. Third Edition ANDREW S. TANENBAUM. Chapter 6 Deadlocks MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 6 Deadlocks Preemptable and Nonpreemptable Resources Non-sharable resource: the resource can be used by only one process at a time A process

More information

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne OPERATING SYSTEMS Prescribed Text Book Operating System Principles, Seventh Edition By Abraham Silberschatz, Peter Baer Galvin and Greg Gagne 1 DEADLOCKS In a multi programming environment, several processes

More information

Final Exam Review. CPSC 457, Spring 2016 June 29-30, M. Reza Zakerinasab Department of Computer Science, University of Calgary

Final Exam Review. CPSC 457, Spring 2016 June 29-30, M. Reza Zakerinasab Department of Computer Science, University of Calgary Final Exam Review CPSC 457, Spring 2016 June 29-30, 2015 M. Reza Zakerinasab Department of Computer Science, University of Calgary Final Exam Components Final Exam: Monday July 4, 2016 @ 8 am in ICT 121

More information

COSC243 Part 2: Operating Systems

COSC243 Part 2: Operating Systems COSC243 Part 2: Operating Systems Lecture 17: CPU Scheduling Zhiyi Huang Dept. of Computer Science, University of Otago Zhiyi Huang (Otago) COSC243 Lecture 17 1 / 30 Overview Last lecture: Cooperating

More information

Introduction to OS. Deadlock. MOS Ch. 6. Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1

Introduction to OS. Deadlock. MOS Ch. 6. Mahmoud El-Gayyar. Mahmoud El-Gayyar / Introduction to OS 1 Introduction to OS Deadlock MOS Ch. 6 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Outline What is Deadlock? How to handle Deadlock? Deadlock Detection and Recovery

More information

Operating System Review Part

Operating System Review Part Operating System Review Part CMSC 602 Operating Systems Ju Wang, 2003 Fall Virginia Commonwealth University Review Outline Definition Memory Management Objective Paging Scheme Virtual Memory System and

More information

Topic 4 Scheduling. The objective of multi-programming is to have some process running at all times, to maximize CPU utilization.

Topic 4 Scheduling. The objective of multi-programming is to have some process running at all times, to maximize CPU utilization. Topic 4 Scheduling The objective of multiprogramming is to have some process running at all times, to maximize CPU utilization. The objective of time sharing is to switch the CPU among processes so frequently.

More information

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter Lecture Topics Today: Uniprocessor Scheduling (Stallings, chapter 9.1-9.3) Next: Advanced Scheduling (Stallings, chapter 10.1-10.4) 1 Announcements Self-Study Exercise #10 Project #8 (due 11/16) Project

More information

3.1 (a) The Main Features of Operating Systems

3.1 (a) The Main Features of Operating Systems Chapter 3.1 The Functions of Operating Systems 3.1 (a) The Main Features of Operating Systems The operating system (OS) must provide and manage hardware resources as well as provide an interface between

More information

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006 Operating Systems Comprehensive Exam Spring 2006 Student ID # 3/16/2006 You must complete all of part I (60%) You must complete two of the three sections in part II (20% each) In Part I, circle or select

More information

Wait-For Graph. Exercise. Wait-For Graph. Today. Comp 104: Operating Systems Concepts. Corresponding Wait-For Graph 13/01/2014. Process Scheduling

Wait-For Graph. Exercise. Wait-For Graph. Today. Comp 104: Operating Systems Concepts. Corresponding Wait-For Graph 13/01/2014. Process Scheduling Comp 104: Operating Systems Concepts Process Scheduling Today Deadlock Wait-for graphs Detection and recovery Process scheduling Scheduling algorithms First-come, first-served (FCFS) Shortest Job First

More information

CSE 120. Fall Lecture 8: Scheduling and Deadlock. Keith Marzullo

CSE 120. Fall Lecture 8: Scheduling and Deadlock. Keith Marzullo CSE 120 Principles of Operating Systems Fall 2007 Lecture 8: Scheduling and Deadlock Keith Marzullo Aministrivia Homework 2 due now Next lecture: midterm review Next Tuesday: midterm 2 Scheduling Overview

More information

Module 1. Introduction:

Module 1. Introduction: Module 1 Introduction: Operating system is the most fundamental of all the system programs. It is a layer of software on top of the hardware which constitutes the system and manages all parts of the system.

More information

Some popular Operating Systems include Linux, Unix, Windows, MS-DOS, Android, etc.

Some popular Operating Systems include Linux, Unix, Windows, MS-DOS, Android, etc. 1.1 Operating System Definition An Operating System (OS) is an interface between a computer user and computer hardware. An operating system is a software which performs all the basic tasks like file management,

More information

Operating Systems: Quiz2 December 15, Class: No. Name:

Operating Systems: Quiz2 December 15, Class: No. Name: Operating Systems: Quiz2 December 15, 2006 Class: No. Name: Part I (30%) Multiple Choice Each of the following questions has only one correct answer. Fill the correct one in the blank in front of each

More information

Chapter 6. Deadlocks

Chapter 6. Deadlocks Chapter 6 Deadlocks 6.. Resources 6.. Introduction to deadlocks 6.3. The ostrich algorithm 6.6. Deadlock prevention 6.4. Deadlock detection and recovery 6.5. Deadlock avoidance 6.7. Other issues Learning

More information

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University Frequently asked questions from the previous class survey CS 370: SYSTEM ARCHITECTURE & SOFTWARE [CPU SCHEDULING] Shrideep Pallickara Computer Science Colorado State University OpenMP compiler directives

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Fall 2016 Lecture 8: Scheduling and Deadlock Geoffrey M. Voelker Administrivia Thursday Friday Monday Homework #2 due at start of class Review material for midterm

More information

Deadlocks. Tore Larsen. With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen

Deadlocks. Tore Larsen. With slides from T. Plagemann, C. Griwodz, K. Li, A. Tanenbaum and M. van Steen Deadlocks Tore Larsen With slides from T. Plagemann,. Griwodz, K. Li, A. Tanenbaum and M. van Steen Resources Resource allocation is a central OS concern Examples of computer resources PU Memory Disk drive

More information

Chapter 6 - Deadlocks

Chapter 6 - Deadlocks Chapter 6 - Deadlocks Luis Tarrataca luis.tarrataca@gmail.com CEFET-RJ L. Tarrataca Chapter 6 - Deadlocks 1 / 100 1 Motivation 2 Resources Preemptable and Nonpreemptable Resources Resource Acquisition

More information

OPERATING SYSTEMS. COMS W1001 Introduction to Information Science. Boyi Xie

OPERATING SYSTEMS. COMS W1001 Introduction to Information Science. Boyi Xie 1 OPERATING SYSTEMS COMS W1001 Introduction to Information Science Boyi Xie 2 Announcement Homework 1 is available Grace days A total of 5 days for 5 HWs If all grace days have been used, 50% of the points

More information

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System Preview Process Scheduler Short Term Scheduler Long Term Scheduler Process Scheduling Algorithms for Batch System First Come First Serve Shortest Job First Shortest Remaining Job First Process Scheduling

More information

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable What s An OS? Provides environment for executing programs Process abstraction for multitasking/concurrency scheduling Hardware abstraction layer (device drivers) File systems Communication Do we need an

More information

Back to synchronization

Back to synchronization Back to synchronization The dining philosophers problem Deadlocks o Modeling deadlocks o Dealing with deadlocks Operating Systems, 28, I. Dinur, D. Hendler and R. Iakobashvili The Dining Philosophers Problem

More information

Chapter seven: Deadlock and Postponement

Chapter seven: Deadlock and Postponement Chapter seven: Deadlock and Postponement -One problem that arises in multiprogrammed systems is deadlock. A process or thread is in a state of deadlock if it is waiting for a particular event that will

More information

Multiprogramming. Evolution of OS. Today. Comp 104: Operating Systems Concepts 28/01/2013. Processes Management Scheduling & Resource Allocation

Multiprogramming. Evolution of OS. Today. Comp 104: Operating Systems Concepts 28/01/2013. Processes Management Scheduling & Resource Allocation Comp 104: Operating Systems Concepts Management Scheduling & Resource Allocation Today OS evolution Introduction to processes OS structure 1 2 Evolution of OS Largely driven by desire to do something useful

More information

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University

CS 571 Operating Systems. Midterm Review. Angelos Stavrou, George Mason University CS 571 Operating Systems Midterm Review Angelos Stavrou, George Mason University Class Midterm: Grading 2 Grading Midterm: 25% Theory Part 60% (1h 30m) Programming Part 40% (1h) Theory Part (Closed Books):

More information

Operating System Concepts Ch. 5: Scheduling

Operating System Concepts Ch. 5: Scheduling Operating System Concepts Ch. 5: Scheduling Silberschatz, Galvin & Gagne Scheduling In a multi-programmed system, multiple processes may be loaded into memory at the same time. We need a procedure, or

More information

Yet another synchronization problem

Yet another synchronization problem Yet another synchronization problem The dining philosophers problem Deadlocks o Modeling deadlocks o Dealing with deadlocks Operating Systems, 25, Meni Adler, Danny Hendler & Roie Zivan The Dining Philosophers

More information

Operating Systems. Lecture3.2 - Deadlock Management. Golestan University. Hossein Momeni

Operating Systems. Lecture3.2 - Deadlock Management. Golestan University. Hossein Momeni Operating Systems Lecture3.2 - Deadlock Management Golestan University Hossein Momeni momeni@iust.ac.ir Contents Resources Introduction to deadlocks Why do deadlocks occur? Ignoring deadlocks : ostrich

More information

Computer Systems Assignment 4: Scheduling and I/O

Computer Systems Assignment 4: Scheduling and I/O Autumn Term 018 Distributed Computing Computer Systems Assignment : Scheduling and I/O Assigned on: October 19, 018 1 Scheduling The following table describes tasks to be scheduled. The table contains

More information

Process P holds resource R. Process P is waiting for resource R. P Process P holds T and requests R. R Process Q holds R and requests T

Process P holds resource R. Process P is waiting for resource R. P Process P holds T and requests R. R Process Q holds R and requests T 1 Deadlocks ffl Non-sharable resource: the resource can be used by only one process at a time ffl A process may use a resource in only the following sequence: Request: If the resource cannot be granted,

More information

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science CPU Scheduling Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS, Lahore Pakistan Operating System Concepts Objectives To introduce CPU scheduling, which is the

More information

CISC 7310X. C10: Deadlocks. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/12/2018 CUNY Brooklyn College

CISC 7310X. C10: Deadlocks. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/12/2018 CUNY Brooklyn College CISC 7310X C10: Deadlocks Hui Chen Department of Computer & Information Science CUNY Brooklyn College 4/12/2018 CUNY Brooklyn College 1 Outline Concept of deadlock Necessary conditions Models of deadlocks

More information

Tasks. Task Implementation and management

Tasks. Task Implementation and management Tasks Task Implementation and management Tasks Vocab Absolute time - real world time Relative time - time referenced to some event Interval - any slice of time characterized by start & end times Duration

More information

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses. 1 Memory Management Address Binding The normal procedures is to select one of the processes in the input queue and to load that process into memory. As the process executed, it accesses instructions and

More information

Maximum CPU utilization obtained with multiprogramming. CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait

Maximum CPU utilization obtained with multiprogramming. CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Thread Scheduling Operating Systems Examples Java Thread Scheduling Algorithm Evaluation CPU

More information

Computer Science 4500 Operating Systems

Computer Science 4500 Operating Systems Computer Science 4500 Operating Systems Module 6 Process Scheduling Methods Updated: September 25, 2014 2008 Stanley A. Wileman, Jr. Operating Systems Slide 1 1 In This Module Batch and interactive workloads

More information

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. System Model Deadlock Characterization Methods of handling

More information

Computer-System Architecture (cont.) Symmetrically Constructed Clusters (cont.) Advantages: 1. Greater computational power by running applications

Computer-System Architecture (cont.) Symmetrically Constructed Clusters (cont.) Advantages: 1. Greater computational power by running applications Computer-System Architecture (cont.) Symmetrically Constructed Clusters (cont.) Advantages: 1. Greater computational power by running applications concurrently on all computers in the cluster. Disadvantages:

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 12: Scheduling & Deadlock Priority Scheduling Priority Scheduling Choose next job based on priority» Airline checkin for first class passengers Can

More information

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Week 05 Lecture 18 CPU Scheduling Hello. In this lecture, we

More information

Computer Hardware and System Software Concepts

Computer Hardware and System Software Concepts Computer Hardware and System Software Concepts Introduction to concepts of Operating System (Process & File Management) Welcome to this course on Computer Hardware and System Software Concepts 1 RoadMap

More information

Operating Systems. Deadlock. User OS. Kernel & Device Drivers. Interface Programs. Brian Mitchell - Operating Systems

Operating Systems. Deadlock. User OS. Kernel & Device Drivers. Interface Programs. Brian Mitchell - Operating Systems User OS Kernel & Device Drivers Interface Programs Deadlock 1 Deadlocks Computer resources are full of resources that can only be used by one process at a time Unpredictable results can occur if two or

More information

Introduction. CS3026 Operating Systems Lecture 01

Introduction. CS3026 Operating Systems Lecture 01 Introduction CS3026 Operating Systems Lecture 01 One or more CPUs Device controllers (I/O modules) Memory Bus Operating system? Computer System What is an Operating System An Operating System is a program

More information

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms Operating System Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts Scheduling Criteria Scheduling Algorithms OS Process Review Multicore Programming Multithreading Models Thread Libraries Implicit

More information

General Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to:

General Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to: F2007/Unit5/1 UNIT 5 OBJECTIVES General Objectives: To understand the process management in operating system Specific Objectives: At the end of the unit you should be able to: define program, process and

More information

Frequently asked questions from the previous class survey

Frequently asked questions from the previous class survey CS 370: OPERATING SYSTEMS [CPU SCHEDULING] Shrideep Pallickara Computer Science Colorado State University L14.1 Frequently asked questions from the previous class survey Turnstiles: Queue for threads blocked

More information

Deadlocks Prof. James L. Frankel Harvard University. Version of 7:05 PM 7-Mar-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Deadlocks Prof. James L. Frankel Harvard University. Version of 7:05 PM 7-Mar-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Deadlocks Prof. James L. Frankel Harvard University Version of 7:05 PM 7-Mar-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Introduction to Deadlocks Computer resources Files Database

More information

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Deadlocks. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Deadlocks Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics What is the deadlock problem? Four conditions for deadlock Handling deadlock

More information

2. Which of the following resources is not one which can result in deadlocking processes? a. a disk file b. a semaphore c. the central processor (CPU)

2. Which of the following resources is not one which can result in deadlocking processes? a. a disk file b. a semaphore c. the central processor (CPU) CSCI 4500 / 8506 Sample Questions for Quiz 4 Covers Modules 7 and 8 1. Deadlock occurs when each process in a set of processes a. is taking a very long time to complete. b. is waiting for an event (or

More information

Main Points of the Computer Organization and System Software Module

Main Points of the Computer Organization and System Software Module Main Points of the Computer Organization and System Software Module You can find below the topics we have covered during the COSS module. Reading the relevant parts of the textbooks is essential for a

More information

CSc33200: Operating Systems, CS-CCNY, Fall 2003 Jinzhong Niu December 10, Review

CSc33200: Operating Systems, CS-CCNY, Fall 2003 Jinzhong Niu December 10, Review CSc33200: Operating Systems, CS-CCNY, Fall 2003 Jinzhong Niu December 10, 2003 Review 1 Overview 1.1 The definition, objectives and evolution of operating system An operating system exploits and manages

More information

Concurrency: Deadlock and Starvation. Chapter 6

Concurrency: Deadlock and Starvation. Chapter 6 Concurrency: Deadlock and Starvation Chapter 6 Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involve conflicting needs for resources

More information

Scheduling Mar. 19, 2018

Scheduling Mar. 19, 2018 15-410...Everything old is new again... Scheduling Mar. 19, 2018 Dave Eckhardt Brian Railing Roger Dannenberg 1 Outline Chapter 5 (or Chapter 7): Scheduling Scheduling-people/textbook terminology note

More information

Deadlocks. Operating System Concepts - 7 th Edition, Feb 14, 2005

Deadlocks. Operating System Concepts - 7 th Edition, Feb 14, 2005 Deadlocks Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock 7.2 Silberschatz,

More information

CS3733: Operating Systems

CS3733: Operating Systems CS3733: Operating Systems Topics: Process (CPU) Scheduling (SGG 5.1-5.3, 6.7 and web notes) Instructor: Dr. Dakai Zhu 1 Updates and Q&A Homework-02: late submission allowed until Friday!! Submit on Blackboard

More information

(MCQZ-CS604 Operating Systems)

(MCQZ-CS604 Operating Systems) command to resume the execution of a suspended job in the foreground fg (Page 68) bg jobs kill commands in Linux is used to copy file is cp (Page 30) mv mkdir The process id returned to the child process

More information

Course Syllabus. Operating Systems

Course Syllabus. Operating Systems Course Syllabus. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation of Processes 3. Scheduling Paradigms; Unix; Modeling

More information

Operating Systems Overview. Chapter 2

Operating Systems Overview. Chapter 2 1 Operating Systems Overview 2 Chapter 2 3 An operating System: The interface between hardware and the user From the user s perspective: OS is a program that controls the execution of application programs

More information

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

Deadlocks. Copyright : University of Illinois CS 241 Staff 1 Deadlocks 1 Deadlock Which way should I go? 2 Deadlock I Oh can no! almost I m get stuck! across GRIDLOCK! 3 Deadlock Definition Deadlocked process Waiting for an event that will never occur Typically,

More information

QUESTION BANK UNIT I

QUESTION BANK UNIT I QUESTION BANK Subject Name: Operating Systems UNIT I 1) Differentiate between tightly coupled systems and loosely coupled systems. 2) Define OS 3) What are the differences between Batch OS and Multiprogramming?

More information

Process Management. Deadlock. Process Synchronization. Management Management. Starvation

Process Management. Deadlock. Process Synchronization. Management Management. Starvation Process Management Deadlock 7 Cases of Deadlock Conditions for Deadlock Modeling Deadlocks Strategies for Handling Deadlocks Avoidance Detection Recovery Starvation Process Synchronization Deadlock Starvation

More information

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections ) CPU Scheduling CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections 6.7.2 6.8) 1 Contents Why Scheduling? Basic Concepts of Scheduling Scheduling Criteria A Basic Scheduling

More information

Operating Systems (1DT020 & 1TT802)

Operating Systems (1DT020 & 1TT802) Uppsala University Department of Information Technology Name: Perso. no: Operating Systems (1DT020 & 1TT802) 2009-05-27 This is a closed book exam. Calculators are not allowed. Answers should be written

More information

8th Slide Set Operating Systems

8th Slide Set Operating Systems Prof. Dr. Christian Baun 8th Slide Set Operating Systems Frankfurt University of Applied Sciences SS2016 1/56 8th Slide Set Operating Systems Prof. Dr. Christian Baun Frankfurt University of Applied Sciences

More information

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5 Process Management A process can be thought of as a program in execution. A process will need certain resources such as CPU time, memory, files, and I/O devices to accomplish its task. These resources

More information

CPU scheduling. Alternating sequence of CPU and I/O bursts. P a g e 31

CPU scheduling. Alternating sequence of CPU and I/O bursts. P a g e 31 CPU scheduling CPU scheduling is the basis of multiprogrammed operating systems. By switching the CPU among processes, the operating system can make the computer more productive. In a single-processor

More information

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition,

Chapter 7: Deadlocks. Operating System Concepts 8 th Edition, Chapter 7: Deadlocks, Silberschatz, Galvin and Gagne 2009 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To present a number

More information

Subject Teacher: Prof. Sheela Bankar

Subject Teacher: Prof. Sheela Bankar Peoples Empowerment Group ISB&M SCHOOL OF TECHNOLOGY, NANDE, PUNE DEPARTMENT OF COMPUTER ENGINEERING Academic Year 2017-18 Subject: SP&OS Class: T.E. computer Subject Teacher: Prof. Sheela Bankar 1. Explain

More information

Concurrency problems. To do. q Non-deadlock bugs q Resources & deadlocks q Dealing with deadlocks q Other issues q Next Time: I/O and file systems

Concurrency problems. To do. q Non-deadlock bugs q Resources & deadlocks q Dealing with deadlocks q Other issues q Next Time: I/O and file systems Concurrency problems To do q Non-deadlock bugs q Resources & deadlocks q Dealing with deadlocks q Other issues q Next Time: I/O and file systems Bugs in some modern applications From some key apps, a summary

More information

CSL373: Lecture 6 CPU Scheduling

CSL373: Lecture 6 CPU Scheduling CSL373: Lecture 6 CPU Scheduling First come first served (FCFS or FIFO) Simplest scheduling algorithm cpu cpu 0 0 Run jobs in order that they arrive Disadvantage: wait time depends on arrival order. Unfair

More information

CS 326: Operating Systems. CPU Scheduling. Lecture 6

CS 326: Operating Systems. CPU Scheduling. Lecture 6 CS 326: Operating Systems CPU Scheduling Lecture 6 Today s Schedule Agenda? Context Switches and Interrupts Basic Scheduling Algorithms Scheduling with I/O Symmetric multiprocessing 2/7/18 CS 326: Operating

More information

Properties of Processes

Properties of Processes CPU Scheduling Properties of Processes CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait. CPU burst distribution: CPU Scheduler Selects from among the processes that

More information

Memory Management. 3. What two registers can be used to provide a simple form of memory protection? Base register Limit Register

Memory Management. 3. What two registers can be used to provide a simple form of memory protection? Base register Limit Register Memory Management 1. Describe the sequence of instruction-execution life cycle? A typical instruction-execution life cycle: Fetches (load) an instruction from specific memory address. Decode the instruction

More information

OPERATING SYSTEM. Functions of Operating System:

OPERATING SYSTEM. Functions of Operating System: OPERATING SYSTEM Introduction: An operating system (commonly abbreviated to either OS or O/S) is an interface between hardware and user. OS is responsible for the management and coordination of activities

More information

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition Chapter 6: CPU Scheduling Silberschatz, Galvin and Gagne 2013 Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Real-Time

More information