Operating Systems Lecture Notes PDF
Document Details
Uploaded by EntrancingOnomatopoeia5884
Tags
Summary
These lecture notes provide a detailed overview of operating systems, focusing on key concepts like process creation, process termination, and CPU scheduling. The document breaks down the process cooperation advantages and introduces the concept of CPU scheduling. The notes aim to educate students on important operating systems principles.
Full Transcript
Computer dept./fourth stage/lect.4(OS) 30/10/23 Context Switch When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. The system does no useful work while switching. 3.6 Methods on proc...
Computer dept./fourth stage/lect.4(OS) 30/10/23 Context Switch When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. The system does no useful work while switching. 3.6 Methods on process 1. Process Creation Parent process create children processes such that create other processes, forming a tree of processes. Resource sharing:✦ Parent and children share all resources. ✦ Children share subset of parent’s resources. ✦ Parent and child share no resources. Execution: ✦ Parent and children execute concurrently. ✦ Parent waits until children terminate. Address space: ✦ Child duplicate of parent. ✦ Child has a program loaded into it. UNIX examples ✦ fork system call creates new process ✦ exec system call used after a fork to replace the process’ memory space with a new program. Process Termination Process executes last statement and asks the operating system to decide it (exit). ✦ Output data from child to parent (via wait). ✦ Process’ resources are deallocated by operating system. Parent may terminate execution of children processes (abort). ✦ Child has exceeded allocated resources. ✦ Task assigned to child is no longer required. ✦ Parent is exiting. ✔ Operating system does not allow child to continue if its parent terminates. ✔ Cascading termination. 2. Cooperating Processes The concurrent processes executing in the OS may be either independent processes or cooperating processes. A process is independent if it cannot affect or be affected by the other processes executing in the system. Clearly, any process that does not share any data (temporary or persistent) with any other process is independent. While a process is cooperating if it can affect or be affected by the other processes executing in the system. Which means any process that shares data with other processes is a cooperating process. The advantages of process cooperation are:- a.Information sharing: Since several users may be interested in the same piece of information (shared file), we must provide an environment to allow concurrent access to these types of resources. 1 Computer dept./fourth stage/lect.4(OS) 30/10/23 b.Computation speedup: If we want a particular task to run faster, we must break it into subtasks, each of which will be executing in parallel with the others. Such a speedup can be achieved only if the computer has multiple processing elements (such as CPUS or I/O channels). c.Modularity: to construct the system in a modular fashion, dividing the system functions into separate processes or threads d. Convenience: Even an individual user may have many tasks on which to work at one time. ( user may be editing, printing, and compiling in parallel. Concurrent execution of cooperating processes requires mechanisms that allow processes to communicate with one another and to synchronize their actions. 3.7 CPU Scheduling Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait. CPU burst distribution Alternating Sequence of CPU And I/O Bursts 3.7.1 CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state. 2. Switches from running to ready state. 3. Switches from waiting to ready. 4. Terminates. Scheduling under 1 and 4 is non preemptive. All other scheduling is preemptive. 2 Computer dept./fourth stage/lect.4(OS) 30/10/23 3.7.2 Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: ✦ switching context ✦ switching to user mode ✦ jumping to the proper location in the user program to restart that program Dispatch latency – time it takes for the dispatcher to stop one process and start another running. 3.7.3 Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit Turnaround time – amount of time to execute a particular process Waiting time – amount of time a process has been waiting in the ready queue Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) Optimization Criteria are:- Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time k 3