Slide 1ProcessesTrace of ProcessSlide 4Process state modelsTwo-State Process ModelQueuing DiagramReason for Process CreationReasons for Process TerminationReasons for Process Termination5 Process StatesDiagram of Process StateExample for 3 ProcessesOS Control StructuresProcess Control Block (PCB)Process Control BlockSuspending ProcessesTwo Suspended StatesProcess Scheduling QueuesReady Queue, I/O Device QueuesProcess SchedulingSchedulersProcess SwitchingProcess SwitchingCPU Process SwitchMode switch vs Process switchModes of executionMode, Space and ContextExecution of the OSExecution within user processesUnix Process CreationUnix Process CreationUnix Process Creation (fork)Unix Process Creation (fork)exec Operationsexec Functionswaitpidwaitpid – pid parameterwaitpid – status parameterwaitpid – options parameterwaitpid optionsCSSE 332-01 Operating SystemsProcessesProcessesA process is a program in execution; process execution must progress in sequential fashion. Can be characterized by its trace.The OS interleaves the execution of several processes to maximize processor utilization A process requires resources, which are managed by the operating systemOS supports Inter-Process Communication (IPC) and user creation of processes2Trace of ProcessSequence of instructions that execute for a processDispatcher switches the processor from one process to another34Time slice ~= 1/10th of a secondProcess state modelsThe OS is responsible for interleaving the execution of the processes. It is important to understand the possible behaviors of all the processes and how to react to them. The behavior of processes is described by means of the process state model.5Two-State Process ModelProcess may be in one of two statesRunningNot-running6Queuing Diagram DispatcherProgram that assigns the processor to one process or anotherPrevents a single process from monopolizing processor time7ProcessorEnterQueueDispatchExitPause(a) Queuing diagramReason for Process Creation8Reasons for Process Termination9Reasons for Process Termination105 Process StatesAs a process executes, it changes stateNew: The process is being created.Running: Instructions are being executed.Waiting or blocked: The process is waiting for some event to occur.Ready: The process is waiting to be assigned to a process.Terminate or Exit: The process has finished execution.11Diagram of Process State12Example for 3 Processes13OS Control StructuresProcess Control Block (PCB)Information associated with each process.Process IDProcess stateProgram counter (PC)CPU registers (Context data)CPU scheduling information (Priority)Memory-management information (Memory pointer)Accounting information (Time, acct. #)I/O status information (requests, devices assigned)15Process Control BlockContains the process attributesCreated and manage by the operating systemAllows support for multiple processesProcess = Program code + Data + PCB16Suspending Processes17Two Suspended States18Process Scheduling QueuesJob queue – set of all processes in the system.Ready queue – set of all processes residing in main memory, ready and waiting to execute.Device queues – set of processes waiting for an I/O device.Process migration between the various queues.19Ready Queue, I/O Device Queues20Process Scheduling21SchedulersLong-term scheduler: job schedulerselects which processes should be brought into the ready queue.invoked infrequently (seconds, minutes)controls the degree of multiprogrammingMedium-term scheduler allocates memory for process.invoked periodically or as needed.Short-term scheduler: CPU schedulerselects which process should be executed next and allocates CPU.invoked frequently (ms)22Process SwitchingDefinitionThe activity that occurs when the OS kernel switches between processes in an effort to share the CPU among competing, runable processesActionsSave contents of hardware registers (PC, SP, ...)Load PC with location of resume pointLoad hardware registers with new context if full context switch23Process SwitchingProcess-switch time is overheadCPU utilization affected by quantum and process-switch timeQuantum: Time-slice (max CPU interval) given to a processTime dependent on hardware supportTypesVoluntary: Process blocksInvoluntary: End of time quantum or higher-priority, runable process gets control of CPU24CPU Process Switch25Mode switch vs Process switchWhen a mode switch occurs, the PCB of the process that was running is still marked Running and is not placed in the Blocked or Ready queue However, depending on what caused the mode switch, a process switch could follow26Modes of executionUser mode:Some parts of virtual address space can not be accessedSome instructions (e.g., memory management) can not be executedKernel mode:Can access kernel address spaceIs a fixed part of the virtual address space of every processSystem call puts user into kernel mode27Mode, Space and Context28Application(user space)System callsExceptions(user + system space)Xnot allowedInterrupts,System tasks(user space)Kernel ModeMore privilegesUser ModeProcess ContextKernel ContextSystem callInterrupt occursExecution of the OS29Execution within user processes30Unix Process CreationParents create children results in a tree of processesResource sharingParent and children share all resourcesChildren share subset of parent’s resourcesParent and child share no resourcesExecutionParent and children execute concurrentlyParent waits until children terminate31Unix Process CreationAddress spaceChild duplicate of parentChild has a program loaded into itUNIX examplesfork system call creates new processexec family of system calls used after a fork to replace the process’ memory space with a new program32Unix Process Creation (fork)Allocate new PID and proc structureInit child’s process control block (PCB)Copy parent’s registers to child’s hardware contextCopy parent’s process image to child’sMark child runnable and give to schedulerReturn PID = 0 to child Return child PID to parent33Unix Process Creation (fork)Effects of forkChild gets a copy of its parent’s memoryBUT changes made by child are not reflected in parentEXCEPT a child can affect the I/O state of parentFile descriptors
View Full Document