310 likes | 699 Views
Process Control. Process Control Block (PCB) Process State Information Process Control Information Functions of an Operating-System Kernel Switch a Process Change of Process State Execution of the Operating System. Operating System Control Structures.
E N D
Process Control • Process Control Block (PCB) • Process State Information • Process Control Information • Functions of an Operating-System Kernel • Switch a Process • Change of Process State • Execution of the Operating System
Operating System Control Structures • Schedules and dispatches processed for execution by the processor • Allocates resources to processes (Think about struct rlimt and getrlimit) • Responds to requests by user programs • (Think about getopt) • Tables are constructed for each entity the operating system manages
Memory Tables • Allocation of main memory to processes • Allocation of secondary memory to processes • Protection attributes for access to shared memory regions • Information needed to manage virtual memory
I/O Tables • I/O device is available or assigned • Status of I/O operation • Location in main memory being used as the source or destination of the I/O transfer
File Tables • Existence of files • Location on secondary memory • Current Status • Attributes • Sometimes this information is maintained by a file-management system (Think about struct stat and stat( ) )
Process Table • Process image consists of program, data, stack, and attributes • Attributes • process control block ( Think about Process ID and getpid( ) ) (Think about Resource Limits and getrlimit( ) )
Process State Transition Diagram with Two Suspend States - Seven-State Process Model New Admit Suspend Admit Dispatch Activate Ready, suspend Ready Running Exit Suspend Time out Event Wait Event Occurs Event Occurs Activate Blocked, suspend Blocked Suspend
UNIX Process State Transition Diagram (1) fork Created Preempted return to user not enough memory (swapping system only) enough memory User Running preempt swap out return reschedule process Ready to Run in Memory Ready to Run Swapped swap in system call, interrupt Kernel Running sleep wakeup wakeup interrupt, interrupt return exit swap out Sleep, Swapped Asleep in Memory Zombie
UNIX Process State Transition Diagram (2) • User running: Executing in user mode. • Kernel running: Executing in kernel model. • Ready to run, in memory: Ready to run as soon as the kernel schedules it.
UNIX Process State Transition Diagram (3) • Asleep in memory: unable to execute until an event occurs; process in main memory. • Ready to run, swapped: process is ready to run, but the the swapper must swap the process into main memory before the kernel can schedule it to execute. • Sleeping, swapped: The process is awaiting an event and has been swapped to secondary storage.
UNIX Process State Transition Diagram (4) • Preempted: process is returning from kernel to user mode, but the kernel preempts it and does a process switch to schedule another process. • Created: process is newly created and not yet ready to run. • Zombie: process no longer exists, but it leaves a record for its parent process to collect.
Process Control BlockProcess Identification • Process Control Block The collection of attributes is refereed to as process control block. • Unique numeric identifier • may be an index into the primary process table
UNIX Process Control Table • Process Identifiers ID of this process and ID of parent process. • User Identifiers real user ID, effective user ID • Pointers To U area and process memory (text, data, stack) • Process Size, Priority, Signal, Timers, ......
Processor State Information • Contents of processor registers • User-visible registers (data/address register). • Control and status registers (program counter, instruction register. • Stack pointers ( points to the top of the stack). • Program status word (PSW) • contains status information - indicate the mode of execution (user or kernel mode) ??????
Question 1Process Control - Exercise/Home Work • The VAX/VMS operating system makes use of four processor access modes as follows: • Kernel: Executes the kernel of the VMS operating system, which includes memory management, interrupt handing, and I/O operations. • Executive: Executes many of the operating system service calls, including file and disk management routines. • Supervisor: Executes other operating system services, such as responses to user command. • User: Execute user programs, plus utilities such as compilers, editors, linkers, and debuggers.
Question 1Process Control - Exercise/Home Work • a) A number of operating systems have two modes (UNIX), kernel and user. What are the advantages and disadvantages of providing four mode instead of two? • b) Can you make a case for even more than four modes?
Typical Functions of an Operating-System Kernel (1) Memory Management • Allocation of address space to processes • Page and segment management I/O Management • Allocation of I/O channels and devices to processes Support Functions • Interrupt handling and accounting
Typical Functions of an Operating-System Kernel (2) Process Management • Process creation and termination • Process scheduling and dispatching • Process switching • Process synchronization and support for inter-process communication
Receive Message from Child Processes * wait( ) System Call * Status Information of wait( ) * Example: communication between parent process and child processes (jg73.cc and jg74.cc)
Process Control Information • Additional information needed by the operating system to control and coordinate the various active processes • scheduling and state information • data structuring • interprocess communication • process privileges • resource ownership and utilization ??????
Event 1 Wait Event 1 Occurs Event 1 Queue Event 2 Wait Event 2 Occurs Event 2 Queue Question 2: Multiple Blocked QueuesProcess Control - Exercise/Home Work Ready Queue Release Dispatch Admit Processor Time-out
Question 2Process Control - Exercise/Home Work • Figure “Multiple Blocked Queues” suggests that a process can only be in one Event queue at a time. • a) Is it possible that you would to allow a process to wait on more than one event at the same time? Provide an example. • b) In that case, how you modify the queuing structure of the figure to support this new feature?
When to Switch a Process • Trap • error occurred • may cause process to be moved to Exit state • Supervisor call • such as file open
When to Switch a Process • Memory fault • memory address is in virtual memory so it must be brought into main memory • Interrupts ?????? • Clock • process has executed for the maximum allowable time slice • I/O
Question 3Process Control - Exercise/Home Work • In a number of early computers, an interrupt cased the register values to be stored in fixed locations associated with the given interrupt signal. • Under what circumstances is this a practical technique? Explain why it is inconvenient in general.
Execution of the Operating System • Nonprocess Kernel • execute kernel outside of any process • operating system code is executed as a separate entity that operates in privileged mode P1 P2 ..... Pn Kernel
Execution of the Operating System • Execution Within User Processes • operating system software within context of a user process • process executes in privileged mode when executing operating system code P1 P2 ...... Pn OS OS OS Functions Functions Functions Process Switching Functions
Execution of the Operating System • Process-Based Operating System • major kernel functions are separate processes • a process is invoked by the operating system P1 P2 ...... Pn OS1 OS2 ..... OSn Process Switching Functions
Question 4Process Control - Exercise/Home Work UNIX is unsuitable for real-time applications, because a process executing in kernel mode may not be preempted . Elaborate. P1 P2 ...… Pn OS OS OS Functions Functions Functions Process Switching Functions
Question 5Process Control - Exercise/Home Work • The UNIX kernel will dynamically grow a process’s stack in virtual memory as needed, but it will never try to shrink it. • Explain why it would be possible to shrink the stack, and • Why the UNIX kernel does not shrink it.