1 / 27

TDC 311

TDC 311. OS Process Description and Control. OS States. An operating system (as any program) is always in a current state It moves from one state to the next as it performs operations It is very important that you don’t move into a state that is a “black hole”

rich
Télécharger la présentation

TDC 311

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. TDC 311 OS Process Description and Control

  2. OS States • An operating system (as any program) is always in a current state • It moves from one state to the next as it performs operations • It is very important that you don’t move into a state that is a “black hole” • Likewise, “miracle” states should not exist • Let’s consider a very simple two-state model for an OS (on the whiteboard)

  3. Reasons for Process Creation • New batch job • Interactive log on • Created by OS to provide a service • Spawned by an existing process (for purposes of modularity or to exploit parallelism)

  4. Reasons for Process Termination • Normal completion • Time limit exceeded • Memory unavailable • Bounds violation • Protection error • Arithmetic error • Time overrun (process has waited too long for an event to happen) • I/O failure

  5. Reasons for Process Termination • Invalid instruction • Privileged instruction • Data misuse • Operator or OS intervention • Parent termination • Parent request

  6. Five-state Model • What if the process has to wait for something to finish (like I/O)? • Let’s consider a five-state model (on the whiteboard)

  7. Five-state Model with Suspend • Let’s add suspend states to our previous five-state model • Use a suspend state when all processes are blocked • When moved to Suspend, process is swapped out to secondary storage, so a new process can be brought in • Suspend Ready – has been suspended and event has occurred • Suspend Blocked – blocked and suspended • Let’s examine this model on the whiteboard

  8. UNIX Process State Transition Diagram • Let’s see how UNIX models its states (on the whiteboard)

  9. Process Description • What is a process made of? • Control structures • Memory tables – keep track of what memory is assigned to what process • I/O tables • File tables • Process tables – keeps a list of pointers to process images

  10. Process Description • A process is also described by its process control block (PCB) • What goes into a PCB? Process attributes • Identifier of this process • Identifier of the process that created this process • User identifier • User-visible registers • Stack pointers • Process state indicator • Scheduler priority indicator • Scheduling-related information

  11. Process Description • What else goes into a PCB? (some more process attributes) • Event (that this process is currently waiting for, if any) • Data structuring (this process may be linked to other processes in a queue, ring, or some other structure) • Various flags, signals, and messages that may be associated with communication between two independent processes • Process privileges (does this process have access to certain system utilities and services?) • Memory management (pointers to segment/page tables) • Resource ownership and utilization (any opened files?)

  12. Process Control • Or, what kinds of “things” can a process do? • But first, a process can be in either user mode or supervisor mode. This determines what a process can or can’t do. • Process can “create” or “spawn” another process • If a process can spawn another process, OS probably does the following: • Assigns a unique PID to new process • Entry added to process table • Allocate space for process image • PCM is initialized • Appropriate linkages are set • Miscellaneous data structures created, accounting updated

  13. Process Control • What else can a process do? • Process can “terminate” another process • Process can “switch” execution to another process • When does a process switch execution? When an interrupt occurs. Currently executing process is switched out, and an interrupt handler or supervisor process is switched in.

  14. Process Switching • What happens when one process switches to another? • Save the context of the current process, including program counter and other registers • Update the PCB of the current process to denote Blocked Ready or whatever • Move the PCB of this process to the appropriate queue • Select the next process for execution • Update the PCB of the selected process • Update memory management structures • Restore the context of the processor to that which existed at the time the selected process was last switched out of the Running state by loading in the previous values of the program counter and other registers

  15. Context Switching • Sometimes it is not necessary to perform a process switch when an interrupt occurs • What if you just want to change the settings on a flag or two? • Don’t do a complete process switch – just do a context switch • Some OSes don’t differentiate between process switching and context switching

  16. Threads • Like lite beer, a thread is a lite process • Each thread may contain: • Thread ID • Program counter • Stack • Register set • Child threads • State • How can it be so lite?

  17. Threads • A thread shares with other threads belonging to the same process • For example, a thread may share: • Code • Data • Other OS resources such as open files and signals • Thus, a group of peer threads share code, address space, and OS resources • One process may have multiple threads • Why a thread? A thread takes far less time to create and move, and much less space

  18. Threads • If threads share things, is security a problem? • No, because the threads do not belong to unrelated competing processes, but to the same process • Threads also make inter-communication easier since multiple threads share the same files and storage • Thread operate pretty much like processes – they have a state, they can get blocked, and they can spawn new threads • There are kernel threads and there are user threads

  19. Common Thread Examples • Database server on a LAN – as each new query arrives, a new thread is spawned to service the request (one process, multiple threads). When one thread gets blocked requesting disk I/O, another thread can start up almost immediately and begin its operation • Web browser – might have one thread display images or text while another thread retrieves data from the network • Word processor – one thread for displaying graphics, another for reading keystrokes from the user, and a third for performing spelling and grammar checking in the background

  20. The Process in VAX/VMS • Let’s consider a more complete example from a real OS (from VAX/VMS OS Concepts by Miller) • “Only way a process can be created is by the action of another process.” • Always some processes running on a system • These processes can be in one of the following states: • SUS – suspended (can be outswapped) • COM – computable (waiting in ready queue)(can be outswapped) • HIB – hibernating (can be outswapped) • LEF – waiting for a local event flag • CUR – currently running; and there are others

  21. The Process in VAX/VMS • Each process has a priority assigned to it • 0 – 31 • 31 is the highest • 4 is typical interactive user • Let’s examine what happens when a user logs in

  22. User Login Procedure • Terminal device reports via interrupt that a key has been pressed • Terminal driver attempts to associate the keystroke to an existing process using the translation table • Since no association exists (new LOGIN), JOB_CONTROL is awakened • JOB_CONTROL calls function $CREPRC which creates a process image which will eventually become the user’s. For now, the new process is just like JOB_CONTROL and has the following information:

  23. ACB (AST Control Block) Forward Link Backward Link Housekeeping ACB Links Physical PCB Ptr Quota Limits Local Event Flags EF Cluster Ptrs PID PHD Ptr JIB Ptr Privileges ACL Links State Priority Name Asynchronous System Traps Process ID PHD (Process Header) Accounting Physical PCB Memory Info (for the code) PCB Vector Job Info Block JIB Access Rights Event Flags, etc. ACL PCB

  24. User LOGIN Procedure continued • All quotas, privileges, priorities are temporarily the same as JOB_CONTROL • Image of LOGINOUT is placed into its PHD Memory Info • $CREPRC marks new process as computable outswapped (COMO) and informs VMS to insert it into the appropriate queue • $CREPRC returns to JOB_CONTROL • JOB_CONTROL hibernates • Eventually the new process gets a chance to execute, which runs LOGINOUT procedure

  25. User LOGIN Procedure continued • LOGINOUT prompts for Username and Password using $QIOW routine • LOGINOUT takes Username and Password and searches file SYSUAF.DAT for valid account

  26. User LOGIN Procedure continued • If account if valid, LOGINOUT extracts following info from user account info: • Process name (usually user name) • Default disk drive and directory info • User privileges • User quotas • Run-time restrictions • Process priority • Default CLI (command line interpreter, or shell) and updates the PCB accordingly

  27. User LOGIN Procedure continued • LOGINOUT initializes the CLI, which is usually DCL program (the standard VAX shell) • DCL eliminates LOGINOUT • DCL executes LOGIN.COM file • DCL puts $ prompt on screen via $QIOW

More Related