1 / 65

Process Description and Control

Process Description and Control. Chapter 3 All multiprogramming OS are built around the concept of processes. A process is also called a task or a job. Roadmap. How are processes represented and controlled by the OS?

trevor
Download Presentation

Process Description and Control

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Process Description and Control Chapter 3 All multiprogramming OS are built around the concept of processes. A process is also called a task or a job.

  2. Roadmap • How are processes represented and controlled by the OS? • Process states and state transitions which characterize the behaviour of processes. • Data structures used to manage processes. • Ways in which the OS uses these data structures to control process execution. • Overview of process management in UNIX SVR4.

  3. OS Requirements for Multiprogramming Process Management • Process management: fundamental OS task • OS must: • interleave the execution of several processes to maximize CPU usage while providing reasonable response time • allocate resources to processes while • protecting processes • enabling synchronization of processes • avoiding deadlock • support inter-process communications to share data and exchange information, and user creation of processes

  4. Concepts • Computer platforms consists of a collection of hardware resources • Computer applications are developed to perform some task • OS provides an interface for applications to use hardware resources • OS provides a representation of resources that can be requested and accessed by application

  5. The OS Manages Execution of Applications Resources are made available to multiple applications The processor or CPU is switched among multiple applications The processor and I/O devices can be used efficiently

  6. What is a “process”? • Aprogram in execution • An instance of a program running on a computer • The entity that can be assigned to and executed on a processor • A unit of activity characterized by the execution of a sequence of instructions, a current state, and an associated set of system instructions/data • More than just source program and data

  7. Process Image • A process is comprised of: • Executable program (possibly shared) • A set of data • A number of attributes describing the context of the process: process-specific context • Process state • Processor status • Other resource data • Stacks

  8. Process Elements • While a process is running, it has a number of elements, including: • Identifier • State • Priority • Program counter • Memory pointers • Context data • I/O status information • Accounting information (?) • ...

  9. Process Control Block (PCB) • Contains the process elements • Created and managed by the operating system • Allows support for multiple processes • Process switching • Interrupt handling for process switching

  10. Dispatcher (short-term scheduler): Process Control and Scheduling • Is part of the OS that moves the processor from one process to another • It prevents a single process from monopolizing processor time • It decides whichgoes next and whenaccording to a scheduling algorithm (to be discussed later) • The CPU will always execute instructions from the dispatcher while switching from process A to process B

  11. Quiz 3-1 • True or False • A process consists of • Source program • Data/stacks • Context/attributes • Give 2 attributes of a process • What are stacks for? • A PCB (Process Control Block) is allocated for • Each process • Multiple processes that are running at the same time • A few processes that shared the same program and data

  12. Roadmap • How are processes represented and controlled by the OS. • Process states and state transitions which characterize the behaviour of processes. • Data structures used to manage processes. • Ways in which the OS uses these data structures to control process execution. • Discuss process management in UNIX SVR4.

  13. Exercise • What are some of the states for a Student Registrar System? • What are some valid state transitions for a Student Registrar System? • What are the similarities and differences between a Student Registrar System and an OS?

  14. Two-State Process Model: A Simple Model • Process may be in one of two states • Running • Not-running

  15. Process Queue and Dispatcher … processes moved by the dispatcher of the OS to the CPU then back to the queue until the task is competed

  16. Process Birth and Death See tables 3.1 and 3.2 for more

  17. Process Creation • The OS builds a data structure to manage the process • Traditionally, the OS creates all processes • But it can be useful to let a running process to create another one • fork() in Unix/Linux (in Lab 2 and assignment 1) • This action is called process spawning • Parent Process is the original, creating process • Child Process is the new process

  18. Process Creation • Assign a unique process identifier • Allocate space for the process image • Initialize process control block • many default values (ex: state is New, inherited values from Parent, …) • Set up appropriate linkages • Ex: add new process to linked list used for the scheduling queue • Create or expand other data structures

  19. Process Termination • There must be some way that a process can indicate completion. • This indication may be: • A HALT instruction generating an interrupt alert to the OS. • A user action (e.g. log off, quitting an application) • A fault or error • Parent process terminating

  20. Process States • Let us expand to these states: • The Running state • The process that gets executed • The Not Running state • The Ready state • any process that is ready to be executed • The Blocked state • when a process cannot execute until some event occurs (ex: the completion of an I/O)

  21. Other Useful States • The New state • OS has performed the necessary initialization actions to create the process • has created a process identifier • has created data structures or tables needed to manage the process • but has not yet committed to execute the process (not yet admitted) • because resources are not allocated or limited

  22. Other Useful States • The Exit state • Termination moves the process to this state • It is no longer eligible for execution • Tables and other info are temporarily preserved for auxiliary program • Ex: accounting program that cumulates resource usage for billing the users • The process (and its tables) gets deleted when the data is no more needed

  23. Process Transitions • Ready --> Running • When it is time, the dispatcher (scheduler) selects a new process to run • Running --> Ready • the running process has expired his time slot • the running process gets interrupted because a higher priority process is in the ready state • How about I/O operations? • Is the process still Ready? • What is the new state?

  24. Process Transitions • Running --> Blocked • When a process requests something for which it must wait • a service that the OS is not ready to perform • an access to a resource not yet available • initiates I/O and must wait for the result • waiting for a process to provide input (IPC) • Blocked --> Ready • When the event for which it was waiting occurs

  25. A Five-state Process Model Ready to exit: A parent may terminate a child process

  26. Quiz 3 • What are the states when a process is not in the Running state? • Describe the state transitions: • Ready  Running • Running  Ready • Ready  Blocked • Running  Blocked • Blocked  Running

  27. Suspended Processes – The Need for Swapping • Processor is faster than I/O, so all processes could be waiting for I/O • Swap these processes to disk to free up more memory and use processor on more processes • Ready/Blocked state becomes suspend state when swapped to disk • Two new states • Blocked Suspend • Ready Suspend

  28. New state transitions (mid-term scheduling) • Blocked --> Blocked Suspend • When all processes are blocked, the OS will make room to bring a ready process in memory • Blocked Suspend --> Ready Suspend • When the event for which it as been waiting occurs (state info is available to OS) • Ready Suspend --> Ready • when “less” ready processes in main memory • Ready--> Ready Suspend (unlikely) • When there are no blocked processes and must free memory for adequate performance

  29. A Seven-state Process Model

  30. Reason for Process Suspension Table 3.3 Reasons for Process Suspension

  31. Quiz 3-2 • Identify the 7 possible process states • Describe the following state transitions • Blocked  Blocked Suspend • Blocked Suspend  Ready Suspend • Ready Suspend  Running

  32. Roadmap • How are processes represented and controlled by the OS. • Process states and transitions which characterize the behaviour of processes. • Data structures used to manage processes. • Ways in which the OS uses these data structures to control process execution. • Discuss process management in UNIX SVR4.

  33. Operating System Control Structures • For the OS is to manage processes and resources, it must have information about the current status of each process and resource. • Tables are constructed for each entity the operating system manages • Memory tables (to be discussed later) • I/O tables (to be discussed later) • File tables (to be discussed later) • Process tables: For OS to manage processes, OS needs to know details: • Current state • Process ID • Location in memory • etc

  34. OS Control Tables

  35. Process Image • User program • User data • Stack(s) • for procedure calls and parameter passing • Process Control Block (execution context) • Data needed (process attributes) by the OS to control the process. This includes: • Process identification information • Processor state information • Process control information

  36. Location of the Process Image • Each process image is in virtual memory • may not occupy a contiguous range of addresses (depends on the memory management scheme used) • both a private and shared memory address spaces are used • The location if each process image is pointed to by an entry in the Primary Process Table • For the OS to manage the process, at least part of its image must be loaded into main memory

  37. Process Identification (in the PCB) • Each process is assigned a unique numeric identifier. • Many of the other tables controlled by the OS may use process identifiers to cross-reference process tables • A few other numeric identifiers are also used, e.g., • User identifier • the user who is responsible for the job • Identifier of the process that created this process

  38. Processor State Information (in PCB) • Contents of processor registers • User-visible registers • Control and status registers • Stack pointers • Program status word (PSW) • contains status information • Example: the EFLAGS register on Pentium machines

  39. Pentium II EFLAGS Register Also see Table 3.6

  40. Process Control Information (in PCB) • The most important data structure in an OS. It defines the state of the OS: • interprocess communication • may hold flags and signals for IPC • process privileges • Ex: access to certain memory locations... • memory management • pointers to segment/page tables assigned to this process • resource ownership and utilization • resource in use: open files, I/O devices... • history of usage (of CPU time, I/O...)

  41. Process Control Information (in PCB) • Scheduling and state information • Process state (i.e., running, ready, blocked...) • Priority of the process • Event for which the process is waiting (if blocked) • Data structure information • may hold pointers to other PCBs for process queues, parent-child relationships and other structures

  42. Queues as linked lists of PCBs

  43. Roadmap • How are processes represented and controlled by the OS. • Process states which characterize the behaviour of processes. • Data structures used to manage processes. • Ways in which the OS uses these data structures to control process execution. • Discuss process management in UNIX SVR4.

  44. Modes of Execution • To provide protection to PCBs (and other OS data) most processors support at least 2 execution modes: • Privileged mode (a.k.a. system mode, kernel mode, supervisor mode, control mode ) • manipulating control registers, primitive I/O instructions, memory management... • User mode • For this the CPU provides a (or a few) mode bit which may only be set by an interrupt or trap or OS call

  45. Switching Processes • Key for multiprogramming • Several design issues are raised regarding process switching • What events trigger a process switch? • We must distinguish between mode switching and process switching. • What must the OS do to the various data structures under its control to achieve a process switch?

  46. When to Switch a Process ? • A process switch may occur whenever the OS has gained control of CPU, i.e., when: • Supervisor Call • explicit request by the program (ex: file open). The process will probably be blocked • Trap • An error resulted from the last instruction. It may cause the process to be moved to the Exit state • Interrupt • the cause is external to the execution of the current instruction. Control is transferred to IH

  47. When to Switch Processes? Summary Table 3.8 Mechanisms for Interrupting the Execution of a Process

  48. Mode Switching • It may happen that an interrupt does not produce a process switch • The control can just return to the interrupted program • Then only the processor state information needs to be saved on stack • This is called mode switching (user to kernel mode when going into IH) • What is the benefit? • Less overhead: no need to update the PCB like for process switching

  49. Steps in Process (Context) Switching • Save context of processor including program counter and other registers • Update the PCB of the running process with its new state and other associate info • Move PCB to appropriate queue - ready, blocked • Select another process for execution • Update PCB of the selected process • Update memory-management data structures • Restore CPU context from that of the selected process

  50. Quiz 3-4 • Identify the causes for process switching • Processing switching: Reorder the tasks: • Update PCB of the selected process • Save context of processor including program counter and other registers • Move PCB to appropriate queue - ready, blocked • Select another process for execution • Update the PCB of the running process with its new state and other associate info • Restore CPU context from that of the selected process • Update memory-management data structures

More Related