Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,

Similar presentations


Presentation on theme: "Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,"— Presentation transcript:

1 Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall

2 Major Functions of an Operating System 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

3 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

4 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?

5 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 –Account numbers

6 Process Control Block Contains the process elements Created and managed by the operating system

7 Process Control Block Allows support for multiple processes

8 Trace of the Process Sequence of instruction that execute for a process Dispatcher switches the processor from one process to another

9 Example Execution

10 Trace of Process

11 Combined Trace of Process

12 Two-State Process Model Process may be in one of two states –Running –Not-running

13 Queuing Diagram

14 Process Creation (I)

15 Example: Application Modularity

16 Example: Concurrent Server Dispatcher process Request dispatched to a worker process Server Worker process

17 What does the OS do to create a process? –Build data structures that are used to manage the process; –Allocate address space in main memory to the process. Process Creation (II)

18 Process Termination

19

20 Queuing Diagram

21 Queuing Processes –Not-running ready to execute –Not-running block –Dispatcher must scan list to find process not- running, ready, and in queue the longest

22 A Five-State Model Running Ready Blocked New Exit

23 Five-State Process Model

24 Process States

25 Using Two Queues

26 Multiple Blocked Queues

27 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

28 Two Suspend States

29 Reason for Process Suspension

30 Processes and Resources

31 In-Class Exercise Running BlockedReady : process blocks for input 2: scheduler picks another process 3: scheduler picks this process 4: input becomes available 5: process blocks for input 6: input becomes available Which state transition is impossible?

32

33 Operating System Control Structures Information about the current status of each process and resource Tables are constructed for each entity the operating system manages So, what control tables does an OS have

34 OS Control Tables

35 Memory Tables (1) Used to keep track of both main (real) memory and secondary (virtual) memory Some of main memory reserved for OS The remainder is available for processes Processes are maintained on secondary memory

36 Memory Tables (2) Allocation of main memory to processes Allocation of secondary memory to processes Protection attributes for access to shared memory regions Information needed to manage virtual memory

37 I/O Tables Used by OS to manage I/O devices and channels of the computer system I/O device is available or assigned Status of I/O operation Location in main memory being used as the source or destination of the I/O transfer

38 File Tables Existence of files Location on secondary memory Current Status Attributes Sometimes this information is maintained by a file management system, OS has little or no knowledge of files In other OS, detailed file management is by OS itself

39 Process Tables Manage processes What is a process composed of? Process image is the collection of program, data, stack, and attributes

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

41 Process Location Where are the processes located? –Secondary memory, usually disk –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

42 Process Images

43 PCB: Process Control Information

44 Data Structuring –A process may be linked to other process in a queue, ring, or some other structure. For example, all processes in a waiting state 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. PCB: Process Control Information

45 Modes of Execution User mode –Less-privileged mode –User programs typically execute in this mode System mode, control mode, or kernel mode –More-privileged mode –Kernel of the operating system

46 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

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

48 When to Switch Process Trap –error or exception occurred –may cause process to be moved to Exit state Supervisor call (system call) –I/O operation such as file open –Lead to a transfer to an OS routine

49 How to Switch Process?

50 Process Switch (1) 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

51 Process Switch (2) Select another process for execution Update the process control block of the process selected Update memory-management data structures –Depending on how address translation is managed, memory management data structures need to be updated Restore context of the selected process

52 Execution of the Operating System Non-process Kernel –Execute kernel outside of any process –Operating system code is executed as a separate entity that operates in privileged mode Execution Within User Processes –Operating system software within context of a user process

53 Execution of the Operating System Process-based operating system –Implement the OS as a collection of system processes

54 Execution of the Operating System

55 OS Executes in User Space

56 Process Switch vs. Mode Switch

57 Process Switch (1) 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

58 Process Switch (2) Select another process for execution Update the process control block of the process selected Update memory-management data structures Restore context of the selected process

59 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

60 UNIX Process States

61 UNIX Process State Transition Diagram

62 fork() Process creation in Unix is 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.

63

64 Reminder 13 students still haven’t formed project teams Team needs to be formed by this Friday!

65 Appendix

66 Elements of a Process Control Block How to assign a process an identifier? may be an index into the process table or process identifier  process table index useful for cross-reference by other tables, inter-process communication

67 Elements of a Process Control Block

68 Review Questions What does it mean to preempt a process? What is swapping and what is its purpose? For what types of entities does the OS maintain tables of information for management purposes? List three general categories of information in a process control block.


Download ppt "Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,"

Similar presentations


Ads by Google