1 / 28

Process Abstraction and Management

Process Abstraction and Management. Fred Kuhns (fredk@arl.wustl.edu, http://www.arl.wustl.edu/~fredk) Department of Computer Science and Engineering Washington University in St. Louis. Process control subsystem. protection. IPC. Synchronization And deadlock. Scheduler. Other

tucker
Download Presentation

Process Abstraction and Management

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 Abstraction and Management Fred Kuhns (fredk@arl.wustl.edu, http://www.arl.wustl.edu/~fredk) Department of Computer Science and Engineering Washington University in St. Louis

  2. Process control subsystem protection IPC Synchronization And deadlock Scheduler Other Resources Interrupt Exceptions Process table char block Device drivers Recall the Model execution environment application trap libraries user System call interface kernel System Services Kernel interface handlers File Subsystem Memory Subsystem hardware Cs422 – Operating Systems Organization

  3. The Process Abstraction • Process: program in execution • Sequential execution, characterized by trace. • Explicitly allocate resources • Memory for data and code • Files for persistent storage and communication • Other resources • Implicit resource allocation • interleave execution of several processes • Notion of fairness, deadlines, throughput • Application creates, destroys processes • Synchronization, Sharing, Communication and deadlock control Cs422 – Operating Systems Organization

  4. Open file table Pending Requests … Memory mappings Example: Process Representation Process P2 State Hardware State (registers) init P0 Program counter Kernel Process Table … P0: HW state; resources Process P3 Memory base … Process State (logical) P2: HW state; resources Process P1 … PN: HW state; resources Process P2 Cs422 – Operating Systems Organization

  5. Dispatch Not Running Running Exit (Terminate) Enter (New) Pause Processor Simple Two-State Model (a) State transition diagram Queue (Runnable) Enter (New) Dispatch (Run) Exit (Terminate) Pause (timeout) (b) Queuing diagram Cs422 – Operating Systems Organization

  6. New Ready Exit Running Blocked 5 State Model – More realistic dispatch • New: The process is being created. • Running: Instructions being executed. • Blocked(waiting): Must wait for some event to occur. • Ready: Runnable but waiting to be assigned to a processor. • Exit (terminate): The process has finished execution. admit time-out event release wait Cs422 – Operating Systems Organization

  7. Example for 3 Processes Cs422 – Operating Systems Organization

  8. Suspending Processes • 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 • Blocked state becomes suspend state when swapped to disk • Two new states • Blocked, suspend • Ready, suspend Cs422 – Operating Systems Organization

  9. New Ready Exit Running Ready Suspend Blocked Suspend Blocked Suspending a Process suspend dispatch admit time-out suspend event admit release activate wait suspend event activate Cs422 – Operating Systems Organization

  10. 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 Cs422 – Operating Systems Organization

  11. 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 Cs422 – Operating Systems Organization

  12. 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. Cs422 – Operating Systems Organization

  13. Ready Queue, I/O Device Queues Cs422 – Operating Systems Organization

  14. Process Scheduling Cs422 – Operating Systems Organization

  15. 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) Cs422 – Operating Systems Organization

  16. CPU Context Switch Cs422 – Operating Systems Organization

  17. 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. Cs422 – Operating Systems Organization

  18. Process Creation • Parents create children; results in a tree of processes. • Resource sharing models: • Parent and children share all resources. • Children share subset of parent’s resources. • Parent and child share no resources. • Address space models: • Child duplicate of parent. • Child has a program loaded into it. • Execution models: • Parent and children execute concurrently. • Parent waits until children terminate. • 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. Cs422 – Operating Systems Organization

  19. Process Termination • Process executes last statement (exit). • Output data from child to parent • 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. Cs422 – Operating Systems Organization

  20. 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 Cs422 – Operating Systems Organization

  21. UNIX Specifics • The following slides are for your benefit and will not be covered in class Cs422 – Operating Systems Organization

  22. 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 Cs422 – Operating Systems Organization

  23. 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 Cs422 – Operating Systems Organization

  24. 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 • 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 Cs422 – Operating Systems Organization

  25. 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) Cs422 – Operating Systems Organization

  26. U Area (user space) 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 (kernel) process ID and group u area pointer process state queue pointers - scheduler, sleep, etc. Priority memory management info flags U area and Proc structures Cs422 – Operating Systems Organization

  27. User Credentials • Every user is assigned a unique user id (uid) and group id (gid). • Superuser (root) has uid == 0 and gid == 0 • every process both a real and effective pair of Ids. • effective id => file creation and access, • real id => sending signals. • Senders real/effective == receivers real Cs422 – Operating Systems Organization

  28. Processes in UNIX • Creating Processes: • fork() • create a new process • copy of parents virtual memory • parent return value is child’s PID • child return value is 0 • exec() • overwrite with new program • Terminating processes: • exit() is called • closes open files • releases other resources • saves resource usage statistics and exit status in proc structure • wakeup parent • calls swtch • Process is in zombie state • parent collects, via wait(), exit status and usage Cs422 – Operating Systems Organization

More Related