Olabisi Onabanjo University, Ago Iwoye. Ogun State. Nigeria. Faculty of Science Department of Mathematical Sciences

Size: px
Start display at page:

Download "Olabisi Onabanjo University, Ago Iwoye. Ogun State. Nigeria. Faculty of Science Department of Mathematical Sciences"

Transcription

1 Olabisi Onabanjo University, Ago Iwoye. Ogun State. Nigeria. Faculty of Science Department of Mathematical Sciences BSc- Lecture Note: OPERATING SYSTEM Objectives: To learn the fundamental of Operating System (OS), the mechanism of OS to handle process and threads and their communication. The mechanisms involve in memory manage ment, filing system and device in OS concepts. The components and management aspects of concurrency management and knowledge on distributed operating system concepts. Course Outlines: Introduction: Overview of OS. Basic OS functions and the historical development Processes Management: Process, Process Control Block. Process State, Scheduling (CPU Utilisation and task scheduling), Concurrency (mutual exclusion, synchronisation, deadlock, starvation, race condition) Memory Management: Physical and Virtual memory, Scheduling Input/Output: Disk request scheduling File Management: Overview, file Organization and access, file directories, File sharing, Record blocking, secondary storage management, File system protection and security FUNDAMENTALS OF OPERATING SYSTEM Computing machines have been increasing in complexity for many centuries, but only recently have they become complex enough to require something recognisable as an operating system. What is Operating System? An operating system is system software that act as an intermediary and enables the computer hardware to communicate and operate with the computer software which hide the complexities of hardware from the user and manage between the hardware s resources. An operating system can also be defined as one program running at all times on the computer (usually called the kernel), with all its applications programs and provide an environment in which a user can execute program.

2 An operating system is an important part of almost every computer system. A computer system can be divided into four components: the hardware, the operating system, the applications programs, and the users. The hardware includes the Central Processing Unit (CPU), the memory, and the input/output (I/O) devices - provides the basic computing resources while the applications programs such as compilers, database systems, games, and business programs define the ways in which these resources are used to solve the computing problems of the users. An operating system is a control program that executes user programs to prevent errors and improper use of the computer. It is especially concerned with the operation and control of I/O devices. Functions of Operating System Operating System has following functions: It manages the computer s resources such as CPU, memory, file and devices. Behaves as a Virtual Machine Establish a user s interface Execute and provide services for application software Historical Development of Operating System For those who grew up having an entire computer sitting at their finger tips waiting at their beck and call to carry out every command, it is hard to imagine punching a program into punch cards, submitting it over a Dutch door and then waiting at least 24 hours to get a printout of the run. Or, even worse, driving 30 miles and waiting one week between program submission and receipt of the printout. But, to understand how today s operating systems came to be what they are, we need to go back to those days of yesteryear, as the saying goes. The chief function of an operating system is to manage the resources of a complex computer system. It has been said that necessity is the mother of invention. The development of operating systems to their present day form is a good illustration of that. At each stage in this development, bottlenecks were found which prevented using the computer resources to their fullest capacity. The need to eliminate those bottlenecks gave impetus to inventiveness leading to the next step in the history of operating systems. The development describes along with the particular type of operating system. Stages of Development The Earliest Computer: The earliest computers did not have software. Their functionality was hardwired. To reprogram the machine required rewiring. These machines, of course, did not have an operating system. User Setup and Breakdown: With the advent of the stored program machine the day of the von Neumann architecture machines began. But the early machines were very costly, available only to clients with deep pockets. When it was not uncommon to pay thousands of dollar for a computer, those who used

3 these machines for business or research were willing to go to great lengths just to get their moment in the sun. Computers were scheduled around the clock and users had to come in at their scheduled time. In addition to load their programs, the users had to load (and link, if necessary) any system software, such as compilers and device drivers, needed for their run. And additional work was required to make the machine available for the next user. Operator Controlled Machines: Very soon it became clear that during the rather lengthy setup and breakdown time the very expensive computer was not doing useful work. This waste of resources had to be remedied. A computer operator was put in charge of the machine. Users submitted their programs on punch cards. The operator scheduled job execution, loaded the programs, collected the output and performed any required setup operations. By running jobs with similar system requirements in the same time frame, the setup and breakdown process was streamlined. Jobs could also be arranged by priority, run time and other criteria. Simple Batch Systems To further reduce slack time, the amount of time during which the computer did no useful work, the scheduling and loading functions were turned over to a program called the monitor (called a resident monitor, if it stayed in memory at all times). Users submitted short instructions in a cryptic language called Job Control Language (JCL) to aid the monitor in its task. Jobs were grouped together and run in batches. Often a separate computer was used to handle the I/O operations. Debugging for this and other early systems was accomplished by interpreting a core dump, a hexadecimal snapshot of the contents of memory and all registers at the time of program error. Hardware features such as memory protection, timers, privileged instructions and interrupts were added to machines during this stage of development. On, the computer components were separated SPOOLING When a job is executed, the operating system satisfies its requests for card reader input by reading from the disk and when the job requests the printer to output a line that line is copied into a system buffer and is written to the disk. When the job is completed, the output is actually printed. This form of processing is called spooling i.e. Simultaneous Peripheral Operation On-Line. Spooling uses the disk as a huge buffer, for reading as far ahead as possible on input devices and for storing output files until the output devices are able to accept them. Spooling is also used for processing data at remote sites. The CPU sends the data via communications paths to a remote printer. The remote processing is done at its own speed, with no CPU intervention. The CPU just needs to be notified when the processing is completed, so that it can spool the next batch of data.

4 Spooling overlaps the I/O of one job with the computation of other jobs. Spooling has a direct beneficial effect on the performance of the system. Spooling can keep both the CPU and the I/O devices working at much higher rates Multiprogrammed Batch Systems Spooling provides an important data structure (A job pool). Spooling will generally result in several jobs that have already been read waiting on disk, ready to run. A pool of jobs on disk allows the operating system to select which job to run next, to increase CPU utilization. An I/O operation is orders of magnitude slower than instruction execution. For this reason the processor would sit idle a large proportion of the time, despite the efficiency improvements brought about by batch systems. Instead of doing useful work, the processor would wait for an I/O operation to complete. The observation was made that more than one job could be read into memory, allowing the processor to switch back and forth between jobs (or processes). While one process was involved in I/O, another could be running that is making use of the processor. Jobs must be run sequentially, on a first-come, first-served basis. However, when several jobs are on a direct-access device, such as a disk, job scheduling becomes possible. The most important aspect of job scheduling is the ability to multiprogrammmg. Thus, schedulers and memory management modules were added to the software repertoire of an operating system. Interactive Multiprogramming (Time Sharing Systems) The importance of good response time and short turnaround time were factored into the OS design process. The major step taken was the advent of time shared systems. An interactive, or handson, computer system provides on-line communication between the user and the system. The user gives instructions to the operating system or to a program directly, and receives an immediate response. Time sharing, or multitasking, is a logical extension of multiprogramming. Multiple jobs are executed by the CPU switching between them, but the switches occur so frequently that the users may interact with each program while it is running. Since the processor speed was many orders of magnitude faster than the actions taken by the user, under ideal conditions the user could work as if she had sole access to the machine. Time-sharing systems were developed to provide interactive use of a computer system at a reasonable cost. A time-shared operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of a time-shared computer. Single User Multiprogramming With the introduction of personal computer with multiprogramming resulted in extremely useful computer systems. The user could run several processes at one time, doing useful work with one program while waiting for another program to complete its task. In addition, this could perform operations which require two programs to run simultaneously, e.g., copy text from a web page and paste it into a word processing document.

5 Figure 1: Components of Operating System PROCESS AND THREAD MANAGEMENT Process Management The design of an operating system must be done in such a way that all requirements should be fulfilled. The operating system must interleave the execution of multiple processes, to maximize processor utilization while providing reasonable response time. The operating system must allocate resources to processes in conformance with a specific policy The operating system may be required to support Interprocess communication and user creation of processes Program and Process A process is a program in execution. For example, when we write a program for instance in C and compile it, the compiler creates a binary code. The original code and Binary code, both are programs. When we actually run the binary code, it becomes a process. A process is an instance of program execution. A process is an active entity as opposed to a program which is considered to be a passive entity. A single program can create many processes when run multiple times, for example when we open a.exe or binary file multiple times, many instances begin (many processes are created).

6 Attributes or Characteristics of a Process Process has the following Attributes. 1. Process Id: A unique identifier assigned by operating system 2. Process State: Can be ready, running, waiting, finish etc. 3. CPU registers: Like Program Counter (CPU registers must be saved and restored when a process is swapped out and in of CPU) 5. Accounts information: 6. I/O status information: For example devices allocated to process, open files, etc 7. CPU scheduling information: For example Priority All the above attributes of a process are also known as Context of the Process. Every Process has its known Program Control Block (PCB) that is each process will have a unique PCB. All the Above Attributes are the part of the PCB. Process Control Block An operating system maintains a structure called a Process Control Block (PCB) for each of its active processes. The PCB for a process contains or refers to the following kinds of information. Resource Management Information Administrative Information An Execution Snapshot Resource management information includes all information about resources other than the processor that a process is using. This includes page tables and open files and I/O streams. In addition, most operating systems support command-line arguments and environment variables for programs. The resource information for such operating systems contains references to structures containing the command-line arguments and environment variables Administrative information includes a process identifier, resource usage information (such as execution time), process ownership, and any kind of administrative data needed by system administrators for running their system securely. The execution snapshot captures any information about a process that is required to resume its operation from the time when the snapshot was taken. The contents are somewhat dependent on the processor, but always include register and PC contents. Process States The operating system is responsibility is controlling the execution of processes; this includes determining the interleaving pattern for execution and allocating resources to processes. Process Creation: When a new process is to be added to those currently being managed, the operating system builds the data structures that are used to manage the process and allocates address space in main memory to the process. This is the creation of a new process.

7 Process Termination: Any computer system must provide a means for a process to indicate its completion. A batch job should include a Halt instruction or an explicit operating system service call for termination. A process may be in one of two states: Running or Not Running. When the operating system creates a new process, it creates a process control block for the process and enters that process into the system in the Not Running state. The process exists, is known to the operating system, and is waiting to execute. Processes that are not running must be kept in some sort of queue, waiting their turn to execute. There is a single queue in which each entry is a pointer to the process control block of a particular process. A Process is in one of the following five (5) states 1. New: Newly Created Process (or) being created process. The creation transition is caused by a system call instruction for loading a program. A process control block is created for the program. It is initialized so that the process starts with cleared registers and PC set to the program's start (main) address. Usually the operating system sets up three open files: standard input, standard output, and standard error. 2. Ready: After creation Process moves to Ready state, that is process is ready for execution. A process in the ready state has all of the resources that it needs for further execution except for a processor. It is normally held in a ready queue until a processor becomes available. Suspended Ready: When ready queue becomes full, some processes are moved to suspend ready state 3. Run: Currently running process in CPU (only one process at a time can be under execution in a single processor). 4. Wait (or Block): When process request for I/O request. 5. Complete (or terminated): Process Completed its execution. Suspended Block: When waiting queue becomes full. Figure 2: A Process State

8 Modes of Execution Processors support at least two modes of execution. Certain instructions can only be executed in the more-privileged mode. These would include reading or altering a control register, such as the program status word; primitive I/O instructions; and instructions that relate to memory management. The less privileged mode is often referred to as the user mode, because user programs typically would execute in this mode. The more-privileged mode is referred to as the system mode, control mode, or kernel mode. Mode Switch A mode switch occurs when CPU privilege level is changed, for example when a system call is made or a fault occurs. The kernel works in more privileged mode than a standard user task. If a user process wants to access things which are only accessible to the kernel, a mode switch must occur. The currently executing process need not be changed during a mode switch. A mode witch typically occurs for a process context switch to occur. Only the Kernel can cause a context switch. It is necessary to protect the operating system and key operating system tables, such as process control blocks from interference by user programs. In the kernel mode, the software has complete control of the processor and all its instructions, registers, and memory. This level of control is not necessary and for safety is not desirable for user programs. Process Switching Sometimes, a running process is interrupted and the operating system assigns another process to the running state and turns control over to that process, which is defined as process switching. A process switch may occur any time that the operating system has gained control from the currently running process. When does Process switching happen? 1. When a high priority process comes to ready state, compared to priority of running process 2. Interrupt occurs 3. User and Kernel mode switch: (It is not necessary) 4. Preemptive CPU scheduling is used. A process switch may occur any time that the operating system has gained control from the currently running process. The main cause is system interrupt i.e. two kinds of system interrupts: Trap Interrupt Trap is event that is external to and independent of the currently running process, such as the completion of an I/O operation. Interrupt relates to an error or exception condition generated within the currently running process, such as an illegal file access attempt. Interrupt, control is first transferred to an interrupt handler, then to an operating system. There are different kinds of Interrupt :

9 Clock interrupt: The operating system determines whether the currently running process has been executing for the maximum allowable unit of time, that is time slice. I/O interrupt: The operating system determines what I/O action has occurred. If the I/O action constitutes an event for which one or more processes are waiting, then the operating system moves all of the corresponding blocked processes to the Ready state. Memory fault: The processor encounters a virtual memory address reference for a word that is not in main memory. The operating system must bring in the block (page or segment) of memory containing the reference from secondary memory to main memory. After the I/O request is issued to bring in the block of memory, the process with the memory fault is placed in a blocked state. With a trap the operating system determines if the error or exception condition is fatal, then the currently running process is moved to the Exit state and a process switch occurs. Threads Management What is a Thread? A thread is a path of execution within a process. However, a process can contain multiple threads. A thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler which is typical a part of OS. Threads in a process can execute different parts of the program code at the same time. They can also execute the same parts of the code at the same time, but with different execution state Modern operating systems allow a process to be divided into multiple threads of execution. T he threads within a process share all process management information except for information directly related to execution. This information is moved out of the PCB into Thread Control Block (TCBs). They have independent current instructions; that is, they have (or appear to have) independent program counters. They are working with different data; that is, they are (or appear to be) working with independent registers. This is accomplished by moving execution state out of the PCB into thread control blocks (TCBs). Each thread has its own TCB. Thread Control Block A thread control block (TCB) contains a thread identifier, a reference to the PCB for the process to which it belongs, a reference to the TCB for the thread that created it, and an execution snapshot. A thread has indirect access to non-execution related resources through the PCB of the process to which it belongs. Thus threads within a process share memory, open files, and I/O streams. Why Multithreading? Thread is also known as lightweight process. The idea is achieve parallelism by dividing a process into multiple threads. For example, in a browser, multiple tabs can be different threads. MS word uses multiple threads, one thread to format the text, other thread to process inputs etc.

10 Difference between Process and Thread The typical difference is that threads within the same process run in a shared memory space, while processes run in separate memory spaces. Threads are not independent of one other like processes as a result threads shares with other threads their code section, data section and OS resources like open files and signals. But, like process, a thread has its own program counter (PC), a register set, and a stack space Thread and Process are two closely related terms in multi-threading. The main difference between the two terms is that the threads are a part of a process, i.e. a process may contain one or more threads, but a thread cannot contain a process. In programming, there are two basic units of execution: processes and threads. They both execute a series of instructions. Both are initiated by a program or the operating system. Faster process switch: Context switch time between threads is less compared to process context switch. Process context switch is more overhead for CPU. Responsiveness: If the process is divided into multiple threads, if one thread completed its execution, then its output can be immediately responded. Effective Utilization of Multiprocessor system: If we have multiple threads in a single process, then we can schedule multiple threads on multiple processor. This will make process execution faster. Resource sharing: Resources like code, data and file can be shared among all threads within a process. Note: stack and registers cannot be shared among the threads. Each thread have its own stack and registers. Communication: Communication between multiple thread is easier as thread shares common address space. while in process we have to follow some specific communication technique for communication between two process. Enhanced Throughput of the system: If process is divided into multiple threads and each thread function is considered as one job, then the number of jobs completed per unit time is increased. Thus, increasing the throughput of the system. Comparison between Process and Thread: Process Definition Process An executing instance of a program is called a process. It has its own copy of the data segment of the parent process. Communication Processes must use interprocess communication to communicate with sibling Thread A thread is a subset of the process. It has direct access to the data segment of its process. Threads can directly communicate with other threads of its process.

11 processes. Overheads Processes have considerable overhead. Creation New processes require duplication of the parent process. Control Processes can only exercise control over child processes. Changes Any change in the parent process does not affect child processes. Threads have almost no overhead. New threads are easily created. Threads can exercise considerable control over threads of the same process. Any change in the main thread may affect the behavior of the other threads of the process. Memory Run in separate memory spaces. Run in shared memory spaces. File descriptors Most file descriptors are not It shares file descriptors. shared. File system There is no sharing of file system context. It shares file system context. Signal It does not share signal It shares signal handling. handling. Controlled by Process is controlled by the Threads are controlled by operating system. programmer in a program. Dependence Processes are independent. Threads are dependent. Process Synchronisation On the basis of synchronisation, processes are categorized as one of the following two types: Independent Process: Execution of one process does not affect the execution of other processes. Cooperative Process: Execution of one process affects the execution of other processes. Therefore, Process synchronization problem arises in the case of Cooperative process also because resources are shared in Cooperative processes. These leads to Critical Section Problem. Critical section is a code segment that can be accessed by only one process at a time. Critical section contains shared variables which need to be synchronized to maintain consistency of data variables. Semaphores A Semaphore is an integer variable, which can be accessed only through two operations wait() and signal(). In the entry section, the process requests for entry in the Critical Section.

12 There are two types of Semaphores: Binary Semaphores and Counting Semaphores Binary Semaphores: They can only be either 0 or 1. They are also known as mutex locks, as the locks can provide mutual exclusion. All the processes can share the same mutex semaphore that is initialized to 1. Then, a process has to wait until the lock becomes 0. Then, the process can make the mutex semaphore 1 and start its critical section. When it completes its critical section, it can reset the value of mutex semaphore to 0 and some other process can enter its critical section. Counting Semaphores: They can have any value and are not restricted over a certain domain. They can be used to control access a resource that has a limitation on the number of simultaneous accesses. The semaphore can be initialized to the number of instances of the resource. Whenever a process wants to use that resource, it checks if the number of remaining instances is more than zero, i.e., the process has an instance available. Then, the process can enter its critical section thereby decreasing the value of the counting semaphore by 1. After the process is over with the use of the instance of the resource, it can leave the critical section thereby adding 1 to the number of available instances of the resource. Any solution to the critical section problem must satisfy three requirements: Mutual Exclusion: If a process is executing in its critical section, then no other process is allowed to execute in the critical section. Progress: If no process is in the critical section, then no other process from outside can block it from entering the critical section. Bounded Waiting: A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted. Peterson s Solution Peterson s Solution is a classical software based solution to the critical section problem. In Peterson s solution, we have two shared variables: boolean flag[i] :Initialized to FALSE, initially no one is interested in entering the critical section int turn : The process whose turn is to enter the critical section.

13 Peterson s Solution preserves all three conditions: Mutual Exclusion is assured as only one process can access the critical section at any time. Progress is also assured, as a process outside the critical section does not blocks other processes from entering the critical section. Bounded Waiting is preserved as every process gets a fair chance. Disadvantages of Peterson s Solution It involves Busy waiting It is limited to 2 processes. TestAndSet TestAndSet is a hardware solution to the synchronization problem. In TestAndSet, there are shared lock variable which can take either of the two values 0 or 1. That is 0 for Unlock and 1 for Lock. Before entering into the critical section, a process inquires about the lock. If it is locked, it keeps on waiting till it become free and if it is not locked, it takes the lock and executes the critical section. In TestAndSet, Mutual exclusion and progress are preserved but bounded waiting cannot be preserved. Usage of Semaphores: Semaphores can be used to deal with n process critical section problem. The n processes shares the semaphores, mutex (standing for mutual exclusion), initialized to 1.) Implementation When-a-process-executes the wait operation and finds that the semaphore value is not positive, it must wait However, rather than busy waiting, the process can block itself. The block operation places a process into a waiting queue associated with the semaphore, and the state of the process is switched to the waiting state. Then, control is transferred to the CPU scheduler, which selects another process to execute

14 A process that is blocked, waiting on a semaphore should be resorted when some other process executes a signal operation. The process is restarted by a wake up operation, which changes the process from the waiting state to the ready state. Priority Scheduling Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms in batch systems. Each process is assigned a priority. Process with the highest priority is to be executed first and so on. Processes with the same priority are executed on first come first served basis. Priority can be decided based on memory requirements, time requirements or any other resource requirement. Implementation: First input the processes with their burst time and priority. Sort the processes, burst time and priority according to the priority. Now simply apply FCFS algorithm. Note: A major problem with priority scheduling is indefinite blocking or starvation. A solution to the problem of indefinite blockage of the low-priority process is aging. Aging is a technique of gradually increasing the priority of processes that wait in the system for a long period of time. Starvation or indefinite blocking is phenomenon associated with the Priority scheduling algorithms, in which a process ready to run for CPU can wait indefinitely because of low priority. In heavily loaded computer system, a steady stream of higher-priority processes can prevent a low-priority process from ever getting the CPU. Deadlocks and Starvation The implementation of a semaphore with a waiting queue may result in situation where two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes. The event in execution of a signal operation. When suc h a state is reached, these processes are said to be deadlocked.

15 Another problem related to deadlocks is indefinite blocking or starvation, a situation where processes wait indefinitely within the semaphore. Indefinite blocking may occur if we add and remove processes from the list associated with a semaphore in LIFO order. Other name of deadlock is Circular Waiting. Other name of starvation is Lived lock. When deadlock occurs no process can make progress, while in starvation apart from the victim process other processes can progress or proceed. Solution to Starvation: Aging Aging is a technique of gradually increasing the priority of processes that wait in the system for a long time. For example, if priority ranges from 127 (low) to 0(high), this could increase the priority of a waiting process by 1 Every 15 minutes. Eventually even a process with an initial priority of 127 would take no more than 32 hours for priority 127 process to age to a priority-0 process. Figure 3: Effect of Time changes on Priority Deadlock Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. Consider an example when two trains are coming toward each other on same track and there is only one track, none of the trains can move once they are in front of each other. Similar situation occurs in operating systems when there are two or more processes hold some resources and wait for resources held by other(s). Deadlock can arise if following four conditions hold simultaneously (Necessary Conditions) Mutual Exclusion: One or more than one resource are non-sharable (Only one process can use at a time). Hold and Wait: A process is holding at least one resource and waiting for resources. No Preemption: A resource cannot be taken from a process unless the process releases the resource. Circular Wait: A set of processes are waiting for each other in circular form. Methods for handling deadlock There are three ways to handle deadlock

16 Deadlock prevention or avoidance: The idea is to not let the system into deadlock state. Deadlock detection and recovery: Let deadlock occur, then do Preemption to handle it once occurred. Ignore the problem all together: If deadlock is very rare, then let it happen and reboot the system. This is the approach that both Windows and UNIX take. Deadlock Detection and Recovery Deadlock Detection 1. If resources have single instance: In this case for Deadlock detection we can run an algorithm to check for cycle in the Resource Allocation Graph. Presence of cycle in the graph is the sufficient condition for deadlock. Figure 4: Process Cycle in Deadlock In the above diagram, resource 1 and resource 2 have single instances. There is a cycle R1 >P1 >R2 >P2. So Deadlock is confirmed. 2. If there are multiple instances of resources: Detection of cycle is necessary but not sufficient condition for deadlock detection, in this case system may or may not be in deadlock varies according to different situations. Deadlock Recovery: Traditional operating system such as Windows doesn t deal with deadlock recovery as it is time and space consuming process. Real time operating systems use Deadlock recovery. Recovery method 1. Killing the Process: Killing all the process involved in deadlock. 2. Resource Preemption: Resources are preempted from the processes involved in deadlock, preempted resources are allocated to other processes, so that there is a possibility of recovering the system from deadlock. In this case systems go into starvation.

17 Deadlock Prevention Deadlock can be prevented by eliminating any of the above four condition discussed. Eliminate Mutual Exclusion: It is not possible to dis-satisfy the mutual exclusion because some resources, such as the tap drive and printer, are inherently non-shareable. Eliminate Hold and wait 1. Allocate all required resources to the process before start of its execution, this way hold and wait condition is eliminated but it will lead to low device utilization. for example, if a process requires printer at a later time and it has to be allocated printer before the start of its execution printer will remained blocked till it has completed its execution. 2. Process will make new request for resources after releasing the current set of resources. This solution may lead to starvation. Eliminate No Preemption: Preempt resources from process when resources required by other high priority process. Eliminate Circular Wait: Each resource will be assigned with a numerical number. A process can request for the resources only in increasing order of numbering. For Example, if P1 process is allocated R5 resources, now next time if P1 ask for R4, R3 lesser than R5 such request will not be granted, only request for resources more than R5 will be granted. Deadlock Avoidance Deadlock avoidance can be done with Banker s Algorithm. Banker s Algorithm is resource allocation and deadlock avoidance algorithm which test all the request made by processes for resources, it check for safe state, if after granting request system remains in the safe state it allows the request and if their is no safe state it don t allow the request made by the process. Inputs to Banker s Algorithm 1. Max need of resources by each process. 2. Currently allocated resources by each process. 3. Max free available resources in the system. Request will only be granted under below condition. 1. If request made by process is less than equal to max need to that process. 2. If request made by process is less than equal to freely available resource in the system.

18 MEMORY MANAGEMENT Memory is central to the operation of a modern computer system. Memory is a large array of words or bytes, each with its own address. Memory is the primary and fundamental power, without which there could be no other intellectual operation. A program resides on a disk as a binary executable file. The program must be brought into memory and placed within a process for it to be executed Depending on the memory management in use the process may be moved between disk and memory during its execution. The collection of processes on the disk that are waiting to be brought into memory for e xecution forms the input queue that is selected one of the process in the input queue and to load that process into memory. The binding of instructions and data to memory addresses can be done at any step along the way: Compile time: If it is known at compile time where the process will reside in memory, then absolute code can be generated. Load time: If it is not known at compile time where the process will reside in memory, then the compiler must generate re-locatable code. Execution time: If the process can be moved during its execution from one memory segment to another, then binding must be delayed until run time. Dynamic Loading Better memory-space utilization can be done by dynamic loading. With dynamic loading, a routine is not loaded until it is called. All routines are kept on disk in a re-locatable load format. The main program is loaded into memory and is executed. The advantage of dynamic loading is that an unused routine is never loaded. Dynamic Linking Most operating systems support only static linking, in which system language libraries are treated like any other object module and are combined by the loader into the binary program image. The concept of dynamic linking is similar to that of dynamic loading. Rather than loading being postponed until execution time, linking is postponed. This feature is usually used with system libraries, such as language subroutine libraries. With dynamic linking, a stub is included in the image for each library-routine reference. This stub is a small piece of code that indicates how to locate the appropriate memory-resident library routing. Overlays The entire program and data of a process must be in physical memory for the process to execute. The size of a process is limited to the size of physical memory. So that a process can be larger than the amount of memory allocated to it, a technique called overlays is sometimes used. The idea of overlays is to keep in memory only those instructions and data that are needed at any given time. When other instructions are needed, they are loaded into space that was occupied previously by instructions that are no longer needed.

19 Example, consider a two-pass assembler. During pass 1, it constructs a symbol table; then, during pass 2, it generates machine-language code. One may be able to partition such an assembler into pass 1 code, pass 2 code, the symbol table 1, and common support routines used by both pass 1 and pass 2. Let us consider Pass1 Pass 2 Symbol table Common routines 30K 70K 80K 20K To load everything at once, we would require 200K of memory. If only 150K is available, we cannot run our process. But pass 1 and pass 2 do not need to be in memory at the same time. We thus define two overlays: Overlay A is the symbol table, common routines, and pass 1, and overlay B is the symbol table, common routines, and pass 2. We add an overlay driver (10K) and start with overlay A in memory. When we finish pass 1, we jump to the overlay driver, which reads overlay B into memory, overwriting overlay A, and then transfers control to pass 2. Overlay A needs only 120K, whereas overlay B needs 130K As in dynamic loading, overlays do not require any special support from the operating system. Logical versus Physical Address Space An address generated by the CPU is commonly referred to as a logical address, whereas an address seen by the memory unit is commonly referred to as a physical address. The compile-time and load-time address-binding schemes result in an environment where the logical and physical addresses are the same. The execution-time address-binding scheme results in an environment where the logical and physical addresses differ. In this case, we usually refer to the logical address as a virtual address. The set of all logical addresses generated by a program is referred to as a logical address space; the set of all physical addresses corresponding to these logical addresses is referred to as a physical address space. The run-time mapping from virtual to physica l addresses is done by the Memory Management Unit (MMU), which is a hardware device. The base register is called a relocation register. The value in the relocation register is added to every address generated by a user process at the time it is sent to memory. The user program deals with logical addresses, therefore, the memory-mapping hardware converts logical addresses into physical addressed. Logical addresses (in the range 0 to max) and Physical addresses (in the range R + 0 to R + max for a base value R). The user generates only logical addresses. The concept of a logical address space that is bound to a separate physical address space is central to proper memory management

20 Swapping A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution. Assume a multiprogrammmg environment with a round robin CPU-scheduling algorithm. When a quantum expires, the memory manager will start to swap out the process that just finished, and to swap in another process to the memory space that has been freed. When each process finishes its quantum, it will be swapped with another process. A variant of this swapping policy is used for priority-based scheduling algorithms. If a higherpriority process arrives and wants service, the memory manager can swap out the lower-priority process so that it can load and execute the higherpriority process. When the higher priority process finishes, the lower-priority process can be swapped back in and continued. This variant of swapping is sometimes called rollout, roll in. A process is swapped out will be swapped back into the same memory space that it occupies previously. If binding is done at assembly or load time, then the process cannot be moved to different location. If execution-time binding is being used, then it is possible to swap a process into a different memory space. Swapping requires a backing store. The backing store is commonly a fast disk. It is large enough to accommodate copies of all memory images for all users. The system maintains a ready queue consisting of all processes whose memory images are on the backing store or in memory and are ready to run. Contiguous Allocation The main memory must accommodate both the operating system and the various user processes. The memory is usually divided into two partitions, one for the resident operating system, and other for the user processes. Single Contiguous Allocation: Simplest allocation method used by MS-DOS. All memory (except some reserved for OS) is available to a process. Partitioned Allocation: Memory is divided in different blocks. In Partition Allocation, when there is more than one partition freely available to accommodate a process s request, a partition must be selected. To choose a particular partition, a partition allocation method is needed. A partition allocation method is considered better if it avoids internal fragmentation. The various partition allocation schemes: 1. First Fit: First partition fitting the requirements, allocate the first hole that is big enough. Searching can start either at the beginning of the set of holes or where the previous first-fit search ended. We can stop searching as soon as we find a free hole that is large enough. Leads to fast allocation of memory space Advantage: Faster in making allocation Disadvantage: Leads to memory waste 2. Best-fit: Allocate the smallest hole that is big enough. We must search the entire list, unless the list is kept ordered by size. This strategy-produces smallest partition fitting the requirements and results in least wasted space. Internal fragmentation reduced but not eliminate.

21 Advantage: Makes the best use of memory space Disadvantage: Slower in making allocation 3. Worst-fit: Allocate the largest hole. Again, we must search the entire list unless it is sorted by size. This strategy produces the largest leftover hole which may be more useful than the smaller leftover hole from a best-t approach. 4. Next Fit: This is similar to the first fit but it will search for the first sufficient partition from the last allocation point. Paged memory management: Memory is divided in fixed sized units called page frames, used in virtual memory environment. Segmented memory management: Memory is divided in different segments (a segment is logical grouping of process' data or code). In this management, allocated memory does not have to be contiguous. Most of the operating systems (for example Windows and Linux) use Segmentation with Paging. A process is divided in segments and individual segments have pages Is Best-Fit really best? Although, best fit minimizes the wastage space, it consumes a lot of processor time for searching the block which is close to required size. Also, Best-fit may perform poorer than other algorithms in some cases. For example, see below exercise. Exercise: Consider the requests from processes in given order 300K, 25K, 125K and 50K. Let there be two blocks of memory available of size 150K followed by a block size 350K. Which of the following partition allocation schemes can satisfy above requests? A) Best fit but not first fit. B) First fit but not best fit. C) Both First fit & Best fit. D) neither first fit nor best fit. Solution: Let us try all options. Best Fit: 300K is allocated from block of size 350K. 50 is left in the block. 25K is allocated from the remaining 50K block. 25K is left in the block. 125K is allocated from 150 K block. 25K is left in this block also. 50K can t be allocated even if there is 25K + 25K space available. First Fit: 300K request is allocated from 350K block, 50K is left out. 25K is be allocated from 150K block, 125K is left out. Then 125K and 50K are allocated to remaining left out partitions. So, first fit can handle requests. So option B is the correct choice.

22 Early Memory Allocation System Types of Early Memory Allocation Schemes: 1. Single-user systems 2. Fixed partitions 3. Dynamic partitions 4. Relocatable dynamic partitions 1. Single-User Contiguous Scheme: Program is loaded in its entirety into memory and allocated as much contiguous space in memory as it needs. Jobs processed sequentially in single-user systems Requires minimal work by the Memory Manager Register to store the base address Accumulator to keep track of the program size Disadvantages of Single-User Contiguous Scheme: Doesn t support multiprogramming Not cost effective 2. Fixed Partitions: Main memory is partitioned; one partition/job. Allows multiprogramming Partition sizes rema in static unless and until computer syste m id shut down, reconfigured, and restarted Requires protection of the job s memory space Requires matching job size with partition size To allocate memory spaces to jobs, the operating system s Memory Manager must keep a table as shown below: Disadvantages: Requires entire program to be stored contiguously Jobs are allocated space on the basis of first available partition of required size Works well only if all of the jobs are of the same size or if the sizes are known aheadof time Arbitrary partition sizes lead to undesired results Too small a partition size results in large jobs having longer turnaround time Too large a partition size results in memory waste or internal fragmentation External and Internal Fragmentation As processes are loaded and removed from memory, the free memory space is broken into little pieces. External fragmentation exists when enough to the memory space exists to satisfy a request, but it is not contiguous; storage is fragmented into a large number of small holes. Depending on the

23 total amount of memory storage and the average process size, external fragmentation may be either a minor or a major problem. Given N allocated blocks, another 0.5N blocks will be lost due to fragmentation. That is, one-third of memory may be unusable. This property is known as the 50 percent rule. Internal fragmentation -memory that is internal to partition, but is not being used. N O T E : J ob 3 m us t w a it e ve n t h ou g h 70K of f r e e space is a v a i la b le in P artition 1 w h e r e Job 1 o c c u p i e s only 30K of the 100K available, T abl e 1 and Figure 5: A Simplifie d Fix e d Part it io n Memo ry 3. Dynamic Partitions: Jobs are given only as much memory as they request when they are loaded Available memory is kept in contiguous blocks Memory waste is comparatively small Disadvantages: Fully utilizes memory only when the first jobs are loaded Subsequent allocation leads to memory waste or external fragmentation

24 Figure 6: A Simplifie d D ynamic Part it io n Memo ry

25 Table 2 and Figure 7: A Simplifie d I nt e rnal Frag me nt at io n

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

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

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

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

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 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

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

Background. Contiguous Memory Allocation

Background. Contiguous Memory Allocation Operating System Lecture 8 2017.5.9 Chapter 8 (Main Memory) Background Swapping Contiguous Memory Allocation Segmentation - Paging Memory Management Selection of a memory-management method for a specific

More information

Announcement. Exercise #2 will be out today. Due date is next Monday

Announcement. Exercise #2 will be out today. Due date is next Monday Announcement Exercise #2 will be out today Due date is next Monday Major OS Developments 2 Evolution of Operating Systems Generations include: Serial Processing Simple Batch Systems Multiprogrammed Batch

More information

Main Memory (Part I)

Main Memory (Part I) Main Memory (Part I) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) Main Memory 1393/8/5 1 / 47 Motivation and Background Amir

More information

Chapters 9 & 10: Memory Management and Virtual Memory

Chapters 9 & 10: Memory Management and Virtual Memory Chapters 9 & 10: Memory Management and Virtual Memory Important concepts (for final, projects, papers) addressing: physical/absolute, logical/relative/virtual overlays swapping and paging memory protection

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

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Operating System Third Year CSE( Sem:I) 2 marks Questions and Answers UNIT I

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Operating System Third Year CSE( Sem:I) 2 marks Questions and Answers UNIT I DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Operating System Third Year CSE( Sem:I) 2 marks Questions and Answers UNIT I 1. What is an Operating system? An operating system is a program that manages

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

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

Operating Systems Unit 6. Memory Management

Operating Systems Unit 6. Memory Management Unit 6 Memory Management Structure 6.1 Introduction Objectives 6.2 Logical versus Physical Address Space 6.3 Swapping 6.4 Contiguous Allocation Single partition Allocation Multiple Partition Allocation

More information

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 8 & Chapter 9 Main Memory & Virtual Memory Chapter 8 & Chapter 9 Main Memory & Virtual Memory 1. Various ways of organizing memory hardware. 2. Memory-management techniques: 1. Paging 2. Segmentation. Introduction Memory consists of a large array

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 2018 L17 Main Memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Was Great Dijkstra a magician?

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

HANDOUTS/ NOTES/ STUDY MATERIAL. Jagannath Institute of Management Sciences Lajpat Nagar OPERATING SYSTEM

HANDOUTS/ NOTES/ STUDY MATERIAL. Jagannath Institute of Management Sciences Lajpat Nagar OPERATING SYSTEM HANDOUTS/ NOTES/ STUDY MATERIAL Jagannath Institute of Management Sciences Lajpat Nagar OPERATING SYSTEM UNIT 1 Introduction/Definition An operating system act as an intermediary between the user of a

More information

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition Chapter 7: Main Memory Operating System Concepts Essentials 8 th Edition Silberschatz, Galvin and Gagne 2011 Chapter 7: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure

More information

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

Operating Systems. Memory Management. Lecture 9 Michael O Boyle Operating Systems Memory Management Lecture 9 Michael O Boyle 1 Memory Management Background Logical/Virtual Address Space vs Physical Address Space Swapping Contiguous Memory Allocation Segmentation Goals

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

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts Memory management Last modified: 26.04.2016 1 Contents Background Logical and physical address spaces; address binding Overlaying, swapping Contiguous Memory Allocation Segmentation Paging Structure of

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

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

Unit-03 Deadlock and Memory Management Unit-03/Lecture-01

Unit-03 Deadlock and Memory Management Unit-03/Lecture-01 1 Unit-03 Deadlock and Memory Management Unit-03/Lecture-01 The Deadlock Problem 1. A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.

More information

Chapter 8: Main Memory

Chapter 8: Main Memory Chapter 8: Main Memory Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the Page Table Example: The Intel 32 and 64-bit Architectures Example:

More information

ROEVER ENGINEERING COLLEGE, PERAMBALUR DEPARTMENT OF INFORMATION TECHNOLOGY OPERATING SYSTEMS QUESTION BANK UNIT-I

ROEVER ENGINEERING COLLEGE, PERAMBALUR DEPARTMENT OF INFORMATION TECHNOLOGY OPERATING SYSTEMS QUESTION BANK UNIT-I systems are based on time-sharing systems ROEVER ENGINEERING COLLEGE, PERAMBALUR DEPARTMENT OF INFORMATION TECHNOLOGY OPERATING SYSTEMS QUESTION BANK UNIT-I 1 What is an operating system? An operating

More information

CS307: Operating Systems

CS307: Operating Systems CS307: Operating Systems Chentao Wu 吴晨涛 Associate Professor Dept. of Computer Science and Engineering Shanghai Jiao Tong University SEIEE Building 3-513 wuct@cs.sjtu.edu.cn Download Lectures ftp://public.sjtu.edu.cn

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

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

Chapter 8: Memory-Management Strategies

Chapter 8: Memory-Management Strategies Chapter 8: Memory-Management Strategies Chapter 8: Memory Management Strategies Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the Page Table Example: The Intel 32 and

More information

Operating Systems. Figure: Process States. 1 P a g e

Operating Systems. Figure: Process States. 1 P a g e 1. THE PROCESS CONCEPT A. The Process: A process is a program in execution. A process is more than the program code, which is sometimes known as the text section. It also includes the current activity,

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

* What are the different states for a task in an OS?

* What are the different states for a task in an OS? * Kernel, Services, Libraries, Application: define the 4 terms, and their roles. The kernel is a computer program that manages input/output requests from software, and translates them into data processing

More information

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective Part I: Operating system overview: Memory Management 1 Hardware background The role of primary memory Program

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 (2INC0) 2017/18

Operating Systems (2INC0) 2017/18 Operating Systems (2INC0) 2017/18 Memory Management (09) Dr. Courtesy of Dr. I. Radovanovic, Dr. R. Mak (figures from Bic & Shaw) System Architecture and Networking Group Agenda Reminder: OS & resources

More information

Model answer of AS-4159 Operating System B.tech fifth Semester Information technology

Model answer of AS-4159 Operating System B.tech fifth Semester Information technology Q.no I Ii Iii Iv V Vi Vii viii ix x Model answer of AS-4159 Operating System B.tech fifth Semester Information technology Q.1 Objective type Answer d(321) C(Execute more jobs in the same time) Three/three

More information

Process Description and Control. Chapter 3

Process Description and Control. Chapter 3 Process Description and Control Chapter 3 Contents Process states Process description Process control Unix process management Process From processor s point of view execute instruction dictated by program

More information

Chapter 9: Virtual-Memory

Chapter 9: Virtual-Memory Chapter 9: Virtual-Memory Management Chapter 9: Virtual-Memory Management Background Demand Paging Page Replacement Allocation of Frames Thrashing Other Considerations Silberschatz, Galvin and Gagne 2013

More information

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES OBJECTIVES Detailed description of various ways of organizing memory hardware Various memory-management techniques, including paging and segmentation To provide

More information

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

Chapter 8: Main Memory. Operating System Concepts 9 th Edition Chapter 8: Main Memory Silberschatz, Galvin and Gagne 2013 Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the Page Table Example: The Intel

More information

6 - Main Memory EECE 315 (101) ECE UBC 2013 W2

6 - Main Memory EECE 315 (101) ECE UBC 2013 W2 6 - Main Memory EECE 315 (101) ECE UBC 2013 W2 Acknowledgement: This set of slides is partly based on the PPTs provided by the Wiley s companion website (including textbook images, when not explicitly

More information

CS420: Operating Systems

CS420: Operating Systems Main Memory James Moscola Department of Engineering & Computer Science York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne Background Program must

More information

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING DEFINITIONS AND TERMINOLOGY Course Name : OPERATING SYSTEMS Course Code : ACS007 Program

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

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem? What is the Race Condition? And what is its solution? Race Condition: Where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular

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

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory Chapter 9: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

Chapter 9 Memory Management

Chapter 9 Memory Management Contents 1. Introduction 2. Computer-System Structures 3. Operating-System Structures 4. Processes 5. Threads 6. CPU Scheduling 7. Process Synchronization 8. Deadlocks 9. Memory Management 10. Virtual

More information

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition Chapter 8: Memory- Management Strategies Operating System Concepts 9 th Edition Silberschatz, Galvin and Gagne 2013 Chapter 8: Memory Management Strategies Background Swapping Contiguous Memory Allocation

More information

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit Memory Management All data in memory before and after processing All instructions in memory in order to execute Memory management determines what is to be in memory Memory management activities Keeping

More information

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1 Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1 Chapter 9: Memory Management Background Swapping Contiguous Memory Allocation Segmentation

More information

CS6401- OPERATING SYSTEM

CS6401- OPERATING SYSTEM 1. What is an Operating system? CS6401- OPERATING SYSTEM QUESTION BANK UNIT-I An operating system is a program that manages the computer hardware. It also provides a basis for application programs and

More information

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering)

Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering) A. Multiple Choice Questions (60 questions) Subject: Operating System (BTCOC403) Class: S.Y.B.Tech. (Computer Engineering) Unit-I 1. What is operating system? a) collection of programs that manages hardware

More information

Interprocess Communication By: Kaushik Vaghani

Interprocess Communication By: Kaushik Vaghani Interprocess Communication By: Kaushik Vaghani Background Race Condition: A situation where several processes access and manipulate the same data concurrently and the outcome of execution depends on the

More information

Chapter 8: Main Memory

Chapter 8: Main Memory Chapter 8: Main Memory Silberschatz, Galvin and Gagne 2013 Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the Page Table Example: The Intel

More information

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100 GATE- 2016-17 Postal Correspondence 1 Operating Systems Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts,

More information

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition Chapter 8: Memory- Management Strategies Operating System Concepts 9 th Edition Silberschatz, Galvin and Gagne 2013 Chapter 8: Memory Management Strategies Background Swapping Contiguous Memory Allocation

More information

Chapter 8: Memory- Management Strategies

Chapter 8: Memory- Management Strategies Chapter 8: Memory Management Strategies Chapter 8: Memory- Management Strategies Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the Page Table Example: The Intel 32 and

More information

Operating System - Overview

Operating System - Overview Unit 37. Operating System Operating System - Overview 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

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

SMD149 - Operating Systems

SMD149 - Operating Systems SMD149 - Operating Systems Roland Parviainen November 3, 2005 1 / 45 Outline Overview 2 / 45 Process (tasks) are necessary for concurrency Instance of a program in execution Next invocation of the program

More information

Administrivia. Deadlock Prevention Techniques. Handling Deadlock. Deadlock Avoidance

Administrivia. Deadlock Prevention Techniques. Handling Deadlock. Deadlock Avoidance Administrivia Project discussion? Last time Wrapped up deadlock Today: Start memory management SUNY-BINGHAMTON CS35 SPRING 8 LEC. #13 1 Handling Deadlock Deadlock Prevention Techniques Prevent hold and

More information

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling Review Preview Mutual Exclusion Solutions with Busy Waiting Test and Set Lock Priority Inversion problem with busy waiting Mutual Exclusion with Sleep and Wakeup The Producer-Consumer Problem Race Condition

More information

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition Chapter 8: Memory Management 8.1 Silberschatz, Galvin and Gagne 2009 Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are

More information

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure.

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure. File Systems I/O Management Hard Drive Management Virtual Memory Swap Memory Management Storage and I/O Introduction CSI3131 Topics Process Management Computing Systems Memory CPU Peripherals Processes

More information

CHAPTER NO - 1 : Introduction:

CHAPTER NO - 1 : Introduction: Sr. No L.J. Institute of Engineering & Technology Semester: IV (26) Subject Name: Operating System Subject Code:21402 Faculties: Prof. Saurin Dave CHAPTER NO - 1 : Introduction: TOPIC:1 Basics of Operating

More information

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition Chapter 8: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 8: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

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

Virtual Memory Outline

Virtual Memory Outline Virtual Memory Outline Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations Operating-System Examples

More information

9.1 Background. In Chapter 6, we showed how the CPU can be shared by a set of processes. As a result of

9.1 Background. In Chapter 6, we showed how the CPU can be shared by a set of processes. As a result of Chapter 9 MEMORY MANAGEMENT In Chapter 6, we showed how the CPU can be shared by a set of processes. As a result of CPU scheduling, we can improve both the utilization of the CPU and the speed of the computer's

More information

CHAPTER 2: PROCESS MANAGEMENT

CHAPTER 2: PROCESS MANAGEMENT 1 CHAPTER 2: PROCESS MANAGEMENT Slides by: Ms. Shree Jaswal TOPICS TO BE COVERED Process description: Process, Process States, Process Control Block (PCB), Threads, Thread management. Process Scheduling:

More information

Last Class: Deadlocks. Where we are in the course

Last Class: Deadlocks. Where we are in the course Last Class: Deadlocks Necessary conditions for deadlock: Mutual exclusion Hold and wait No preemption Circular wait Ways of handling deadlock Deadlock detection and recovery Deadlock prevention Deadlock

More information

Some popular Operating Systems include Linux Operating System, Windows Operating System, VMS, OS/400, AIX, z/os, etc.

Some popular Operating Systems include Linux Operating System, Windows Operating System, VMS, OS/400, AIX, z/os, etc. Operating System Quick Guide https://www.tutorialspoint.com/operating_system/os_quick_guide.htm Copyright tutorialspoint.com Operating System Overview An Operating System OS is an interface between a computer

More information

Department of Computer applications. [Part I: Medium Answer Type Questions]

Department of Computer applications. [Part I: Medium Answer Type Questions] Department of Computer applications BBDNITM, Lucknow MCA 311: OPERATING SYSTEM [Part I: Medium Answer Type Questions] UNIT 1 Q1. What do you mean by an Operating System? What are the main functions of

More information

Memory Management. CSCI 315 Operating Systems Design Department of Computer Science

Memory Management. CSCI 315 Operating Systems Design Department of Computer Science Memory Management CSCI 315 Operating Systems Design Department of Computer Science Notice: The slides for this lecture are based on those from Operating Systems Concepts, 9th ed., by Silberschatz, Galvin,

More information

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science Virtual Memory CSCI 315 Operating Systems Design Department of Computer Science Notice: The slides for this lecture have been largely based on those from an earlier edition of the course text Operating

More information

Chapter 9: Memory Management. Background

Chapter 9: Memory Management. Background 1 Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging 9.1 Background Program must be brought into memory and placed within a process for

More information

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5) Announcements Reading Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) 1 Relationship between Kernel mod and User Mode User Process Kernel System Calls User Process

More information

Roadmap. Tevfik Koşar. CSC Operating Systems Spring Lecture - XII Main Memory - II. Louisiana State University

Roadmap. Tevfik Koşar. CSC Operating Systems Spring Lecture - XII Main Memory - II. Louisiana State University CSC 4103 - Operating Systems Spring 2007 Lecture - XII Main Memory - II Tevfik Koşar Louisiana State University March 8 th, 2007 1 Roadmap Dynamic Loading & Linking Contiguous Memory Allocation Fragmentation

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

UNIT I PROCESSES AND THREADS

UNIT I PROCESSES AND THREADS 2 MARKS QUESTIONS AND ANSWERS 16 MARKS QUESTION BANK 1.What is an operating system? UNIT I PROCESSES AND THREADS An operating system is a program that manages the computer hardware. it act as an intermediate

More information

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Processes Prof. James L. Frankel Harvard University Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Process Model Each process consists of a sequential program

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

Following are a few basic questions that cover the essentials of OS:

Following are a few basic questions that cover the essentials of OS: Operating Systems Following are a few basic questions that cover the essentials of OS: 1. Explain the concept of Reentrancy. It is a useful, memory-saving technique for multiprogrammed timesharing systems.

More information

CHAPTER 6: PROCESS SYNCHRONIZATION

CHAPTER 6: PROCESS SYNCHRONIZATION CHAPTER 6: PROCESS SYNCHRONIZATION The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. TOPICS Background

More information

UNIT 4 DEADLOCKS 4.0 INTRODUCTION

UNIT 4 DEADLOCKS 4.0 INTRODUCTION UNIT 4 DEADLOCKS Deadlocks Structure Page Nos 4.0 Introduction 69 4.1 Objectives 70 4.2 Deadlocks 70 4.3 Characterisation of a Deadlock 71 4.3.1 Mutual Exclusion Condition 4.3.2 Hold and Wait Condition

More information

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed. CHAPTER 8: MEMORY MANAGEMENT By I-Chen Lin Textbook: Operating System Concepts 9th Ed. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Segmentation Paging Structure of the

More information

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3 Operating Systems Antonio Vivace - 2016 revision 4 Licensed under GPLv3 Process Synchronization Background A cooperating process can share directly a logical address space (code, data) or share data through

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

Fall 2015 COMP Operating Systems. Lab 06

Fall 2015 COMP Operating Systems. Lab 06 Fall 2015 COMP 3511 Operating Systems Lab 06 Outline Monitor Deadlocks Logical vs. Physical Address Space Segmentation Example of segmentation scheme Paging Example of paging scheme Paging-Segmentation

More information

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging Chapter 8: Memory Management Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging 1 Background Memory management is crucial in better utilizing one of the most important

More information

Virtual Memory - Overview. Programmers View. Virtual Physical. Virtual Physical. Program has its own virtual memory space.

Virtual Memory - Overview. Programmers View. Virtual Physical. Virtual Physical. Program has its own virtual memory space. Virtual Memory - Overview Programmers View Process runs in virtual (logical) space may be larger than physical. Paging can implement virtual. Which pages to have in? How much to allow each process? Program

More information

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 8: Virtual Memory. Operating System Concepts Chapter 8: Virtual Memory Silberschatz, Galvin and Gagne 2009 Chapter 8: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

CS370 Operating Systems Midterm Review

CS370 Operating Systems Midterm Review CS370 Operating Systems Midterm Review Yashwant K Malaiya Fall 2015 Slides based on Text by Silberschatz, Galvin, Gagne 1 1 What is an Operating System? An OS is a program that acts an intermediary between

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