1 / 53

Introducing Processes: Description and Control

Introducing Processes: Description and Control. Fred Kuhns Washington University Computer Science Dept. Processes. A process is a program in execution; process execution must progress in sequential fashion. Can be characterized by its trace.

heloise
Télécharger la présentation

Introducing Processes: 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. Introducing Processes:Description and Control Fred Kuhns Washington University Computer Science Dept.

  2. Processes • A process is a program in execution; process execution must progress in sequential fashion. Can be characterized by its trace. • A process requires resources, which are managed by the operating system • The OS interleaves the execution of several processes to maximize processor utilization • OS supports InterProcess Communication (IPC) and user creation of processes

  3. Process

  4. Process Traces

  5. Running System

  6. Dispatch Exit Running Not Running Enter Pause (a) State transition diagram Simple Two-State Model

  7. Processor Queuing Diagram • Dispatcher • Program that assigns the processor to one process or another • Prevents a single process from monopolizing processor time Dispatch Queue Exit Enter Pause (a) Queuing diagram

  8. 5 Process States • As a process executes, it changes state • New: 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.

  9. Diagram of Process State

  10. Example for 3 Processes

  11. Suspending Processes

  12. Two Suspended States

  13. OS Control Structures Memory Tables Process Image Memory I/O Tables User data User program System stack PCB I/O File File Tables Processes Primary Table Process 1 Process 2 … Process N

  14. Process Control Block (PCB) Information associated with each process. • Process state • Program counter • CPU registers • CPU scheduling information • Memory-management information • Accounting information • I/O status information

  15. Process Scheduling Queues • Job 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.

  16. Ready Queue, I/O Device Queues

  17. Process Scheduling

  18. Schedulers • Long-term scheduler: job scheduler • selects which processes should be brought into the ready queue. • invoked infrequently (seconds, minutes) • controls the degree of multiprogramming • Medium-term scheduler • allocates memory for process. • invoked periodically or as needed. • Short-term scheduler: CPU scheduler • selects which process should be executed next and allocates CPU. • invoked frequently (ms)

  19. CPU Context Switch

  20. Context Switch • When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. • Context-switch time is overhead; the system does no useful work while switching. • Time dependent on hardware support.

  21. Process Creation • Parents create children; results in a tree of processes. • Resource sharing • Parent and children share all resources. • Children share subset of parent’s resources. • Parent and child share no resources. • Execution • Parent and children execute concurrently. • Parent waits until children terminate.

  22. Process Creation (Cont.) • Address space • Child duplicate of parent. • Child has a program loaded into it. • UNIX examples • fork system call creates new process • execve system call used after a fork to replace the process’ memory space with a new program.

  23. Process Termination • Process executes last statement (exit). • Output data from child to parent (via wait). • resources deallocated by operating system. • Parent may terminate execution of children processes (abort). • Child has exceeded allocated resources. • Task assigned to child is no longer required. • Parent is exiting. • Operating system does not allow child to continue • Cascading termination.

  24. Cooperating Processes • Independent process cannot affect or be affected by the execution of another process. • Cooperating process can affect or be affected by the execution of another process • Advantages of process cooperation • Information sharing • Computation speed-up • Modularity • Convenience

  25. Typical UNIX System

  26. char block Device drivers A Traditional UNIX Kernel execution environment application trap libraries user System call interface kernel System Services File subsystem dispatcher IPC Process control subsystem Buffercache Scheduler Exceptions Interrupt Memory hardware

  27. Basic Concepts and Terminology • Two privilege levels • user and system mode • kernel space protected: requires special instruction sequence to change from user to kernel mode • Process has "protected" address space • all process share same kernel space • per process state (u_area) in kernel • per process kernel stack • kernel is re-entrant • system versus process context

  28. Mode, Space and Context Privileged user kernel mode context process Application (user code) System calls Exceptions kernel X not allowed Interrupts, System tasks system space

  29. The UNIX Kernel • loaded at boot time and initializes system, • creates initial system processes. • remains in memory and manages the system • Resource manager/mediator - • process is key abstraction • Time share (time-slice) the CPU, • coordinate access to peripherals, • manage virtual memory. • Performsprivilegedoperations. • provides synchronization primitives. • Well defined entry points • syscall, exceptions or interrupts.

  30. Entry into the Kernel • Synchronous - kernel performs work on behalf of the process: • System call interface (UNIX API): central component of the UNIX API • Hardware exceptions - unusual action of process • Asynchronous - kernel performs tasks that are possibly unrelated to current process. • Hardware interrupts - devices assert hardware interrupt mechanism to notify kernel of events which require attention (I/O completion, status change, real-time clock etc) • System processes - scheduled by OS • swapper and pagedaemon.

  31. Trap or Interrupt Processing • Hardware switches to kernel mode, using the per/process kernel stack. • HW saves PC, Status word and possibly other state on kernel stack. • Assembly routine saves any other information necessary and dispatches event. • On completion a return from interrupt (RFI) instruction is performed.

  32. Interrupt handling • Asynchronous event. • Name three? • Must be serviced in system context, • What does this mean? • Must not block, • Why? • What happens to the currently running process?

  33. Interrupt handling - some details • Multiple interrupt priority levels (ipl), traditionally 0-7. • User processes and kernel operate at the lowest ipl level. • Higher level Interrupts can preempt lower priority ones. • The current ipl level may be set while executing critical code in order to block (or mask) higher priority interrupts.

  34. Exception handling • Synchronous to the currently running process. • What is an example? • Must run in the current processes context. • Why? • An Interrupt may occur during the processing of an exception or trap. • Could this be a problem?

  35. Software Interrupts • Interrupts typically have the highest priority in a system. • Software interrupts are assigned priorities above that of user processes but below that of interrupts. • Software interrupts are typically implemented in software. • Examples are callout queue processing and network packet processing.

  36. System Call Interface • System call API • Why do we need one? • Implemented as a set of assembly language stubs • Trap into kernel dispatch routine which invokes a high-level system call. • User privileges are verified and any data is copied into kernel (copyin()). • On return, copy out any user data (copyout()), check for an Asynchronous System Trap (signal, preemption, etc).

  37. Traditional UNIX Synchronization • Kernel is re-entrant. • only one thread/processes active at any given time (others are blocked). • Nonpreemptive. • Blocking operations • Masking interrupts

  38. Blocking Operations • When resource is unavailable (possibly locked), process sets flag and calls sleep() • sleep places process on a blocked queue, sets state to asleep and calls swtch() • when resource released wakeup() is called • all sleeping processes are woken and state set to runnable (placed on the runnable queues). • When running, process must verify resource is available. Why?

  39. Process Scheduling • Preemptive round-robin scheduling • fixed time quantum • priority is adjusted by nice value and usage factor. • Processes in the kernel are assigned a kernel priority (sleep priority) which is higher than user priorities. • Kernel 0-49, user 50-127.

  40. Signals • Asynchronous events and exceptions • Signal generation using the kill() system call • Default operation or user specific handlers • sets a bit in the pending signals mask in the proc structure • All signals are handled before return to normal processing • System calls can be restarted

  41. The Process • Fundamental abstraction • Executes a sequence of instructions • Competes for resources • Address space - memory locations accessible to process • virtual address space: memory, disk, swap or remote devices • System provides features of a virtual machine • shared resources (I/O, CPU etc) • dedicated registers and memory

  42. The UNIX Process • Most created by fork or vfork • well defined hierarchy: one parent and zero or more child processes. The init process is at the root of this tree • different programs may be run during the life of a process by calling exec • processes typically terminate by calling exit

  43. User Running Kernel Running Runnable Stopped Zombie Initial Idle Stopped Asleep Asleep UNIX Process States fork system call, interrupt return fork swtch() exit swtch() wait sleep() continue stop wakeup stop stop continue wakeup

  44. dispatch admit New Ready Running Exit time-out release activate event wait Suspend Blocked suspend Simpler State Diagram

  45. Process Context • Address Space • text, data, stack, shared memory ... • Control information (u area, proc) • u area, proc structure, maps • kernel stack • Address translation maps • Credentials • user and groupids • Environment variables • variable=value • typically stored at bottom of stack

  46. Process Context (cont) • Hardware context • program counter • stack pointer • processor status word • memory management registers • FPU registers • Machine registers saved in u area's process control block (PCB) during context switch to another process

  47. Kernel stack stack Process address space Data Text (shared) 0x00000000 Process Address Space 0xffffffff Kernel address space 0x7fffffff

  48. proc struct User Stack User Stack User Stack Big Picture kernel memory Kernel stack/u area Kernel stack/u area Kernel stack/u area Data Data Data Text (shared) Text (shared) Text (shared)

  49. Control Information • U area. • Part of user space (above stack). • typically mapped to a fixed address. • contains info needed with running. • Can be swapped • Proc • contains info needed when not running. • Not swapped out. • traditionally fixed size table

  50. U Area PCB - HW context pointer to proc real/effective ids args, return values or errors to current syscall. Signal info file descriptor table controlling terminal vnode Proc structure process ID and group u area pointer process state queue pointers - scheduler, sleep, etc. Priority memory management info flags U area and Proc structures

More Related