1 / 70

Chapter 3: Processes

Chapter 3: Processes. Prerequisite Test Results. 80% of students are familiar with C/C++ Total score is 120 Above 80: 0 70-79: 3 60-69: 6 50-59: 6 40-49: 6 Below 40: 11. Objectives. To introduce the notion of a process

athenar
Download Presentation

Chapter 3: Processes

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. Chapter 3: Processes

  2. Prerequisite Test Results • 80% of students are familiar with C/C++ • Total score is 120 • Above 80: 0 • 70-79: 3 • 60-69: 6 • 50-59: 6 • 40-49: 6 • Below 40: 11

  3. Objectives • To introduce the notion of a process • To describe process scheduling, creation, termination, and communication • To explore interprocess communication using shared memory and message passing • To describe communication in client-server systems

  4. OS Major Functions • Interleave the execution of multiple processes, to maximize processor utilization while providing reasonable response time • Allocate resources to processes • Support interprocess communication and user creation of processes

  5. Process • A program 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 • an associated set of system resources

  6. Process Concept • Multiple parts • The program code, also called text section • Current activity context including programcounter, processor registers • Stackcontaining temporary data • Function parameters, return addresses, local variables • Data sectioncontaining global variables • Heapcontaining memory dynamically allocated during run time

  7. Process Concept (Cont.) • Program is passive entity stored on disk (executable file), process is active • Program becomes process when executable file loaded into memory • How to execute a program? • Execution of a program starts via GUI mouse click, command line entry of its name, etc. • Can we have one program in several processes? • Consider multiple users executing the same program on cse.unl.edu server

  8. Process in Memory

  9. Process Stack Parameter passing in a read procedure call: Figure (a) The stack before the call to read. (b) The stack while the called procedure is active.

  10. Process State • As a process executes, it changes state • new: The process is being created • running: Instructions are being executed • waiting: The process is waiting for some event to occur • e.g., a completion of an I/O operation or • a semaphore signal from another process • ready: The process is waiting to be assigned to a processor • terminated: The process has finished execution

  11. Diagram of Process State

  12. Process Elements (I) • Identifier • State • Priority • Program counter • Memory pointers: to code and data How to describe a process? What elements are included in it?

  13. Process Elements (II) • Context data: value of CPU registers • I/O status information • Outstanding I/O requests • Assigned I/O devices and used files • Accounting information • Amount of processor time & clock time used • Time limits

  14. Process Control Block (PCB) • Each process is represented by a PCB • Created and managed by the operating system • Contains the process elements

  15. Process Control Block • Allows support for multiple processes

  16. OS Control Tables Tables are constructed for each entity (i.e., process, resource) the operating system manages

  17. Process Tables • Manage processes • A process is composed of program, data, heap, stack, and attributes ---- process image • User Data • The modifiable part of the user space, including data section and heap. • User Program • The program to be executed. • Stack • Each process has one or more last-in-first-out (LIFO) stacks associated with it. A stack is used to store parameters and returning addresses for procedure and system calls. • Process Control Block • Data needed by the OS to control the process

  18. Process Location • Where are the processes located? • To manage and execute a process, at least a small portion of its image must be maintained in main memory • OS must know the location of each page of each process image, achieved by process tables

  19. Process Images

  20. PCB: Process Control Information • Data structuring: a process may be linked to other process in a queue, ring, or some other structure. • For example, all ready processes for a particular priority level may be linked in a queue. • A process may exhibit a parent-child (creator-created) relationship with another process. • The process control block may contain pointers to other processes to support these structures.

  21. Process Creation • Assign a unique process identifier • Allocate space for the process • Initialize process control block • Set up appropriate linkages • Create or expand other data structures

  22. When to Switch Process • Clock interrupt • process has executed for the maximum allowable time slice • I/O interrupt • Memory fault • memory address is in disk so it must be brought into main memory

  23. When to Switch Process • Trap • error or exception occurred • may cause process to be moved to Exit state • System Call • Inter-process communication • I/O operation such as file open • Lead to a transfer to an OS routine

  24. How to Switch Process?

  25. CPU Switch From Process to Process

  26. Process (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 via a context switch • Context of a process represented in the PCB • Context-switch time is overhead; the system does no useful work while switching • The more complex the OS and the PCB  the longer the context switch • Time dependent on hardware support • Some hardware provides multiple sets of registers per CPU  multiple contexts loaded at once

  27. Process (Context) Switch • Save context of processor including program counter and other registers • Update the process control block of the process that is currently in the Running state • Move process control block to appropriate queue – e.g., ready; blocked • Select another process for execution • Update the process control block of the process selected • Restore context of the selected process • Update memory-management data structures (page tables, TLB, etc.)

  28. Execution of the OS Funtions • Process Switch vs. • Mode Switch

  29. Execution of the Operating System • Process-based operating system • Implement the OS as a collection of system processes • Process switch for OS service

  30. Execution of the Operating System • Execution Within User Processes • Operating system software within context of a user process • Mode switch for OS service

  31. OS Executes in User Space • Mode switch for OS service

  32. Process vs. Mode Switch • Save context of processor including program counter and other registers • Update the process control block of the process that is currently in the Running state • Move process control block to appropriate queue – ready; blocked; ready/suspend • Select another process for execution • Update the process control block of the process selected • Restore context of the selected process • Update memory-management data structures

  33. Mode Switch • Save context of processor including program counter and other registers • Update the process control block of the running process • Mode changes to kernel mode, finishes the OS routine • Mode changes back, restore the context, and continue the running process in user mode

  34. Process Scheduling (I) • What does process scheduling do? • What is the objective of doing process scheduling?

  35. Process Scheduling (II) • To maximize CPU use and for time sharing, quickly switch processes onto CPU • Process scheduler selects among available processes for next execution on CPU • OS maintains scheduling queues of processes • Ready queues – set of all processes residing in main memory, ready and waiting to execute • Device queues – set of processes waiting for an I/O device • Processes migrate among the various queues

  36. Process Scheduling (III) • Three different categories of process scheduler • Short-term scheduler • Long-term scheduler • Medium-term scheduler

  37. Short-term Scheduler • Short-term scheduler (or CPU scheduler or Dispatcher) – selects which process should be executed next and allocates CPU • Sometimes the only scheduler in a system • Short-term scheduler is invoked frequently (milliseconds)  (must be fast) • Trace of the Process • Sequence of instructions that execute for a process • Dispatcher switches the processor from one process to another  Interleaving process traces

  38. Example Execution

  39. Trace of Process

  40. Combined Trace of Process

  41. Long-term Scheduler • Long-term scheduler (or job scheduler) – selects which processes should be admitted (i.e., brought into ready queue) • The long-term scheduler controls the (maximum) degree of multiprogramming • Long-term scheduler is invoked infrequently (seconds, minutes)  (may be slow) • Processes can be described as either: • I/O-bound process • – spends more time doing I/O than computations, many short CPU bursts • CPU-bound process • – spends more time doing computations; few very long CPU bursts • Long-term scheduler strives for good process mix

  42. Addition of Medium Term Scheduling • Medium-term scheduler can be added if (actual) degree of multiprogramming needs to change • Remove process from memory, store on disk, bring back in from disk to continue execution: swapping • Present in all systems with virtual memory (Chap 9)

  43. Suspended Processes • Processor is faster than I/O so all executable processes could be waiting for I/O, while there are some new processes waiting to be admitted • Swap these processes to disk to free up more memory to admit new processes • Blocked state becomes suspend state when swapped to disk • Two new states • Blocked/Suspend • Ready/Suspend

  44. Two Suspend States

  45. Operations on Processes • System must provide mechanisms for: • process creation, • process termination, • and so on as detailed next

  46. Process Creation • Parentprocess creates childrenprocesses, which, in turn create other processes, forming a tree of processes • Generally, process identified and managed via aprocess identifier (pid) • Resource sharing options • Parent and children share all resources • Children share subset of parent’s resources • Parent and children share no resources • For example, rfork in FreeBSD permits fine-grained sharing of resources between parent and child processes • Execution options • Parent and children execute concurrently (e.g., fork) • Parent waits until children terminate (e.g., vfork)

  47. Process Creation (Cont.) • Address space • Child duplicate of parent • UNIX example • fork()system call creates new process

  48. fork() • Process creation in Unix could be made by means of the kernel system call, fork() • When a process issues a fork request, the OS: • Allocates a slot in the process table for the new process; • Assigns a unique process ID to the child process; • Makes a copy of the process image of the parent, with the exception of any shared memory; • Increments counters for any files owned by the parent, to reflect that an additional process now also owns those files; • Assigns the child process to the Ready to Run state; • Returns the ID number of the child to the parent process, and a 0 value to the child process.

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

More Related