2Major Functions of an Operating System Interleave the execution of multiple processes, to maximize processor utilization while providing reasonable response timeAllocate resources to processesSupport interprocess communication and user creation of processes
3Process A program in execution An instance of a program running on a computerThe entity that can be assigned to and executed on a processorA unit of activity characterized bythe execution of a sequence of instructionsa current statean associated set of system resources
4How to describe a process? What elements are included in it? Process Elements (I)IdentifierStatePriorityProgram counterMemory pointers: to code and dataHow to describe a process? What elements are included in it?
5Process Elements (II) Context data: value of CPU registers I/O status informationOutstanding I/O requestsAssigned I/O devices and used filesAccounting informationAmount of processor time & clock time usedTime limitsAccount numbers
6Process Control Block Contains the process elements Created and managed by the operating system
7Process Control BlockAllows support for multiple processes
8Trace of the ProcessSequence of instruction that execute for a processDispatcher switches the processor from one process to another
23Five-State Process Model New: a process that has just been created but has not yet been admitted to the pool of executable processes by the OS. Typically, a new process had not been loaded into main memory, although its process control block has been created.
27Suspended ProcessesProcessor is faster than I/O so all executable processes could be waiting for I/O, while there are some new processes waiting to be admittedSwap these processes to disk to free up more memory to admit new processesBlocked state becomes suspend state when swapped to diskTwo new statesBlocked/SuspendReady/Suspend
31Which state transition is impossible? In-Class ExerciseRunning21635BlockedReady41: process blocks for input2: scheduler picks another process3: scheduler picks this process4: input becomes available5: process blocks for input6: input becomes availableWhich state transition is impossible?
33Operating System Control Structures Information about the current status of each process and resourceTables are constructed for each entity the operating system managesSo, what control tables does an OS have
35Memory Tables (1)Used to keep track of both main (real) memory and secondary (virtual) memorySome of main memory reserved for OSThe remainder is available for processesProcesses are maintained on secondary memory
36Memory Tables (2) Allocation of main memory to processes Allocation of secondary memory to processesProtection attributes for access to shared memory regionsInformation needed to manage virtual memory
37I/O TablesUsed by OS to manage I/O devices and channels of the computer systemI/O device is available or assignedStatus of I/O operationLocation in main memory being used as the source or destination of the I/O transfer
38File Tables Existence of files Location on secondary memory Current StatusAttributesSometimes this information is maintained by a file management system, OS has little or no knowledge of filesIn other OS, detailed file management is by OS itselfStatus: text file, binary file, directory etc.
39Process Tables Manage processes What is a process composed of? Process image is the collection of program, data, stack, and attributes
40Process StackFigure 4-5. (a) Parameter passing in a procedure call: the stack before the call to read. (b) The stack while the called procedure is active.
41Process Location Where are the processes located? Secondary memory, usually diskTo manage and execute a process, at least a small portion of its image must be maintained in main memoryOS must know the location of each page of each process image, achieved by process tables
44PCB: Process Control Information Data StructuringA process may be linked to other process in a queue, ring, or some other structure. For example, all processes in a waiting state for a particular priority level may be linked in a queue. A process may exhibit a parent-child (creator-created) relationship with another process. The process control block may contain pointers to other processes to support these structures.
45Modes of Execution User mode System mode, control mode, or kernel mode Less-privileged modeUser programs typically execute in this modeSystem mode, control mode, or kernel modeMore-privileged modeKernel of the operating system
46Process Creation Assign a unique process identifier Allocate space for the processInitialize process control blockSet up appropriate linkagesCreate or expand other data structures
47When to Switch Process Clock interrupt I/O interrupt Memory fault process has executed for the maximum allowable time sliceI/O interruptMemory faultmemory address is in virtual memory so it must be brought into main memory
48When to Switch Process Trap Supervisor call (system call) error or exception occurredmay cause process to be moved to Exit stateSupervisor call (system call)I/O operation such as file openLead to a transfer to an OS routine
50Process Switch (1)Save context of processor including program counter and other registersUpdate the process control block of the process that is currently in the Running stateMove process control block to appropriate queue – ready; blocked; ready/suspend
51Process Switch (2) Select another process for execution Update the process control block of the process selectedUpdate memory-management data structuresDepending on how address translation is managed, memory management data structures need to be updatedRestore context of the selected process
52Execution of the Operating System Non-process KernelExecute kernel outside of any processOperating system code is executed as a separate entity that operates in privileged modeExecution Within User ProcessesOperating system software within context of a user process
53Execution of the Operating System Process-based operating systemImplement the OS as a collection of system processes
57Process Switch (1)Save context of processor including program counter and other registersUpdate the process control block of the process that is currently in the Running stateMove process control block to appropriate queue – ready; blocked; ready/suspend
58Process Switch (2) Select another process for execution Update the process control block of the process selectedUpdate memory-management data structuresRestore context of the selected process
59Mode SwitchSave context of processor including program counter and other registersUpdate the process control block of the running processMode changes to kernel mode, finishes the OS routineMode changes back, restore the context, and continue the running process in user modeA mode switch may occur without changing the state of the process that is currently in the Running state. Therefore, the context saving and subsequent restoration involve little overhead.
62fork()Process creation in Unix is made by means of the kernel system call, fork()When a process issues a fork request, the OS:Allocates a slot in the process table for the new process;Assigns a unique process ID to the child process;Makes a copy of the process image of the parent, with the exception of any shared memory;Increments counters for any files owned by the parent, to reflect that an additional process now also owns those files;Assigns the child process to the Ready to Run state;Returns the ID number of the child to the parent process, and a 0 value to the child process.
66Elements of a Process Control Block How to assign a process an identifier?may be an index into the process tableor process identifier process table indexuseful for cross-reference by other tables, inter-process communication
68Review Questions What does it mean to preempt a process? What is swapping and what is its purpose?For what types of entities does the OS maintain tables of information for management purposes?List three general categories of information in a process control block.