1 Lecture 3: Processes Operating System Fall 2006.

Slides:



Advertisements
Similar presentations
©2009 Operačné systémy Procesy. 3.2 ©2009 Operačné systémy Process in Memory.
Advertisements

Dr. Kalpakis CMSC 421, Operating Systems. Fall Processes.
Abhinav Kamra Computer Science, Columbia University 4.1 Operating System Concepts Silberschatz, Galvin and Gagne  2002 Chapter 4: Processes Process Concept.
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Process Description and Control Chapter 3. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Adapted from slides ©2005 Silberschatz, Galvin, and Gagne Lecture 4: Processes.
Chapter 3: Processes.
Chapter 3 Processes.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
1/30/2004CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Process Concept n An operating system executes a variety of programs: –Batch system – jobs –Time-shared systems – user programs or tasks n Textbook uses.
Chapter 3: Processes. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
1 Lecture 4: Processes Operating System Spring 2007 Chapter 4 of textbook.
1/26/2007CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Silberschatz and Galvin  Operating System Concepts Module 4: Processes Process Concept Process Scheduling Operation on Processes Cooperating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chap 3 Processes-Concept. Process Concept Process – a program in execution; process execution must progress in sequential fashion A process includes:
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operation on Processes.
Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems.
Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Process Concept Process – a program.
Chapter 3 Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Jan 19, 2005 Chapter 3: Processes Process Concept.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 4 Process Slide 1 Chapter 4 Process.
AE4B33OSS Chapter 3: Processes. 3.2Silberschatz, Galvin and Gagne ©2005AE4B33OSS Chapter 3: Processes Process Concept Process Scheduling Operations on.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Outline n Process Concept n Process.
Chapter 3: Processes (6 th edition chap 4). 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Chapter 3: Processes. 3.2CSCI 380 Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication.
1 11/1/2015 Chapter 4: Processes l Process Concept l Process Scheduling l Operations on Processes l Cooperating Processes l Interprocess Communication.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
CS212: OPERATING SYSTEM Lecture 2: Process 1. Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 3 Operating Systems.
Chapter 3: Process-Concept. Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
3.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Overview: Process Concept Process Scheduling Operations on Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Jan 19, 2005 Chapter 3: Processes Process Concept.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Jan 19, 2005 Chapter 3: Processes Process Concept.
Chapter 3: Processes-Concept. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes-Concept Overview Process Scheduling.
Process Description and Control Chapter 3. Source Modified slides from Missouri U. of Science and Tech.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
Lecture 4: Processes & Threads. Lecture 4 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents The concept of Process Process states and life-cycle.
 Process Concept  Process Scheduling  Operations on Processes  Cooperating Processes  Interprocess Communication  Communication in Client-Server.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server.
Chapter 3: Process-Concept. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 3: Process-Concept Process Concept Process Scheduling.
4.1 Operating System Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
XE33OSA Chapter 3: Processes. 3.2XE33OSASilberschatz, Galvin and Gagne ©2005 Chapter 3: Processes Process Concept Process Scheduling Operations on Processes.
Lecture 3 Process.
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Chapter 4: Processes Process Concept Process Scheduling
Processes Overview: Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 4: Processes Process Concept Process Scheduling
Lecture 2: Processes Part 1
Process Description and Control
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Chapter 3: Process Concept
Presentation transcript:

1 Lecture 3: Processes Operating System Fall 2006

2 Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing reasonable response time Allocate resources to processes in conformance with a specific policy while at the same time avoiding deadlock Support interprocess communication and user creation of processes, both of which may aid in the structuring of applications

3 Contents Process Definition Process States Process Scheduling Process Description Process Control and Operations Interprocess Communication

4 Contents Process Definition Process States Process Scheduling Process Description Process Control and Operations Interprocess Communication

5 Processes - Definition Also called a job Execution of an individual program Process components: An executable program – text section The associated data needed by the program Stack – temporary data (e.g. function parameters, return addresses, and local variables) Data section – global variables Heap – memory which is dynamically allocated during process run time The execution context of the program All information the operating system needs to manage the process Including the value of program counter and the contents of the processor’s registers

6 Process in memory

7 Process Trace Processes can be traced For a program to be executed, a process is created for that program. We can characterize the behavior of an individual process by listing the sequence of instructions that execute for that process. Such a listing is called a trace of the process. We can characterizing behavior of the processor by showing how the traces of the various processes are interleaved.

8 Example for processes tracing

9 Process AOSProcess BOSProcess COSProcess AOSProcess C time

10 Example for processes tracing (cont.)

11 Contents Process Definition Process States Process Scheduling Process Description Process Control and Operations Interprocess Communication

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

13 Not-Running Process in a Queue

14 Process State Not-running ready to execute Waiting (also called blocked) waiting for I/O Dispatcher cannot just select the process that has been the longest in the queue because it may be blocked

15 Process State - A Five-State Model New: The process is being created Running: Instructions are being executed Waiting (blocked): The process is waiting for some event to occur Ready: The process is waiting to be assigned to a processor Terminated: The process has finished execution

16 Process State - A Five-State Model

17 Queueing-Diagram Representation of Five-State Model

18 Queueing-Diagram Representation of Five-State Model

19 Suspended Process – The Need for Swapping The three principal states just described (Ready, Running, Waiting/Blocked) provide a systematic way of modeling the behavior of processes and guide the implementation of the OS. However, there is good justification for adding other states to the model – the need for swapping

20 Suspended Process – The Need for Swapping 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 Waiting(Blocked) state becomes suspend state when swapped to disk Two new states Waiting(Blocked), suspend Ready, suspend

21 One Suspend State

22 Two Suspend States

23 Reasons for Process Suspension

24 Contents Process Definition Process Trace Process States Process Scheduling Process Description Process Control and Operations Interprocess Communication

25 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 Processes migrate among the various queues

26 Representation of Process Scheduling (Five-State Model)

27 Schedulers Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU Medium-term scheduler – corresponds to suspended state (swapping out of the memory)

28 Addition of Medium Term Scheduling

29 Schedulers (Cont.) Short-term scheduler is invoked very frequently (milliseconds)  (must be fast) Long-term scheduler is invoked very infrequently (seconds, minutes)  (may be slow) The long-term scheduler controls the degree of multiprogramming 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

30 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

31 Contents Process Definition Process States Process Scheduling Process Description Process Control and Operations Interprocess Communication

32 What information does the OS need to control processes and manage resources for them?

33 Memory Tables Used to keep track of both main(real) and secondary memory. Must include the following information: Allocation of main memory to processes. Allocation of secondary memory to processes. Protection attributes of blocks of main or virtual memory, such as which processes may access certain shared memory regions. Information needed to manage virtual memory.

34 I/O Tables Used by the OS to manage the I/O devices. May include the following information: 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

35 File Tables Provide information about the existence of files: Existence of files Location on secondary memory Current Status Attributes Sometimes this information is maintained by a file-management system

36 Process Tables Used to manage processes Include the following information: Where process is located Depend on the memory management scheme being used. In the simplest case, the process image is maintained as a contiguous block of memory. This block is maintained in secondary memory, usually disk. Attributes necessary for its management Process ID Process state Location in memory

37 Typically Elements of a Process Image User Data The modifiable part of the user space. May include program data, a user stack area, and programs that may be modified. User Program The program to be executed System Stack Each process has one or more system stacks associated with it. A stack is used to store parameters and calling addresses for procedure and system calls. Process Control Block Data needed by the OS to control the process.

38 Process Control Block Process Identification Processor State Information Process Control Information

39 Process Control Block Process Identification Processor State Information Process Control Information

40 Process identification Numeric identifiers that may be stored with the process control block include Identifier of this process Identifier of the process that created this process (parent process) User identifier

41 Process Control Block Process Identification Processor State Information Process Control Information

42 Processor State Information User-Visible Registers Control and Status Registers PC PSW Stack Pointers Each process has one or more system stacks associated with it.

43 Process Control Block Process Identification Processor State Information Process Control Information

44 Process Control Information Scheduling and State Information: Process State (e.g. running, ready, waiting, etc.) Priority Scheduling-related information Depend on the scheduling algorithm used. e.g. amount of time it has already run, how long it has waited Event Identity of event the process is awaiting

45 Process Control Information (cont.) Data Structuring A process may be linked to other processes, e.g to its parent Interprocess Communication Various flags, signals, and messages may be associated with communication between two independent processes. Process Privilege Processes are granted privileges in terms of the memory that may be accessed and the types of instructions that may be executed.

46 Process Control Information (cont.) Memory Management Including pointers to segment and/or page tables that describe the virtual memory assigned to this process. Resource Ownership and Utilization Resources controlled by the process may be indicated, such as opened files. A history of utilization of the processor or other resources may also be included; this information may be needed by the scheduler.

47

48 Contents Process Definition Process States Process Scheduling Process Description Process Control and Operations Interprocess Communication

49 Process Creation When a new process is to be added to those currently being managed, the OS builds the date structures that are used to manage the process and allocates address space in main memory to the process. These actions constitute the creation of a new process.

50 Reasons for Process Creation Submission of a new batch job The OS is provided with a batch job control stream usually a tape or disk Interactive logon A user at a terminal logs on to the system Created by OS to provide a service such as printing The OS can create a process to perform a function on behalf of a user program Spawned by existing process For purposes of modularity or to exploit parallalism, a user program can dictate the creation of a number of processes. When one process spawns another process, the former is called the parent and the spawned process as the child.

51 Procedure for Process Creation Once the OS decides to create a new process, it can proceed as follows: (a) Assign a unique process identifier to the new process (b) Allocate space for the process. (c) Initialize the process control block (d) Set the appropriate linkage e.g. if the OS maintains each scheduling queue as a linked list, then the new process must be put in the ready or ready/suspend list (e) Create or expand other data structures e.g. the OS may maintain an accounting file on each process to be used subsequently for billing and/or performance assessment purpose.

52 Process Creation Parent process create children processes, which, in turn create other processes, forming 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 Address space Child duplicate of parent Child has a program loaded into it

53 Process Creation Example for UNIX 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

54 Process Creation Example for UNIX - C Program Forking Separate Process int main() { Pid_t pid; /* fork another process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit(-1); } else if (pid == 0) { /* child process */ execlp("/bin/ls", "ls", NULL); } else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit(0); }

55 A tree of processes on a typical Solaris

56 Process Termination A batch job should include a Halt instruction or an explicit OS service call for termination. User logs off For an interactive application, there are commands to terminate a process. Control C will terminate a process. Error and fault conditions

57 Reasons for Process Termination Normal completion The process executes an OS service call to indicate that it has completed running. Time limit exceeded The process has run longer than the specified total time limit. Memory unavailable The process requires more memory than the system can provide. Bounds violation The process tries to access a memory location that it is not allowed to access.

58 Reasons for Process Termination (cont.) Protection error The process attempts to use a resource or a file that it is not allowed to use, or tries to use it in an improper fashion. Example: write to read-only file Arithmetic error The process tries a prohibited computation, such as division by zero, or arithmetic overflow. Time overrun process waited longer than a specified maximum for an event I/O failure An error occurs during input or output. Privileged instruction The process attempts to use an instruction reserved for the OS

59 Reasons for Process Termination (cont.) Invalid instruction The process attempts to execute a nonexistent instruction (often as a result of branching into a data area and attempting to execute the data) Data misuse Operating system intervention such as when deadlock occurs Parent terminates so child processes terminate When a parent process terminates, the OS may automatically terminate all of the child processes. Parent request A parent process may terminate any of its child process.

60 Process Switching A running process is interrupted and the OS assigns another process to the Running state and turns control over to that process

61 When to Switch a Process Interrupt 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 Trap error occurred may cause process to be moved to Exit state Supervisor call such as file open

62 Comparison between interrupt, trap and supervisor call MechanismCauseUse InterruptExternal to the execution of the current instruction Reaction to an asynchronous external event TrapAssociated with the execution of the current instruction Handling of an error or an exception condition Supervisor call Explicit requestCall to an OS function

63 Change of Process State 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 Change the state of the process to one of the other states (Ready, waiting, or Exit, etc.) Other relevant fields must also be updated, including the reason for leaving the Running state and accounting information Move process control block to appropriate queue - Ready, Waiting, etc.

64 Change of Process State (cont.) Select another process for execution Update the process control block of the process selected Change the state of this process to Running Update memory-management data structures This may be required, depending on how address translation is done Restore context of the selected process

65 Contents Process Definition Process States Process Scheduling Process Description Process Control and Operations Interprocess Communication

66 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

67 Two IPC Mechanisms Shared mamory A region of memory that is shared by cooperating processes is established. Processes can then exchange information by reading and writing date to the shared region. Message passing Communication takes place by means of messages exchanged between the cooperating processes.

68 Communications Models

69 Example for Shared mamory: Producer-Consumer Problem Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process unbounded-buffer places no practical limit on the size of the buffer bounded-buffer assumes that there is a fixed buffer size

70 Bounded-Buffer – Shared-Memory Solution Shared data #define BUFFER_SIZE 10 Typedef struct {... } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; Solution is correct, but can only use BUFFER_SIZE-1 elements

71 Bounded-Buffer – Insert() Method while (true) { /* Produce an item */ while (((in = (in + 1) % BUFFER SIZE count) == out) ; /* do nothing -- no free buffers */ buffer[in] = item; in = (in + 1) % BUFFER SIZE; }

72 Bounded Buffer – Remove() Method while (true) { while (in == out) ; // do nothing -- nothing to consume // remove an item from the buffer item = buffer[out]; out = (out + 1) % BUFFER SIZE; return item; }

73 Message-Passing Mechanism for processes to communicate and to synchronize their actions Message system – processes communicate with each other without resorting to shared variables providing two operations: send(message) – message size fixed or variable receive(message) If P and Q wish to communicate, they need to: establish a communication link between them exchange messages via send/receive Implementation of communication link physical (e.g., shared memory, hardware bus) logical (e.g., logical properties)

74 Direct Communication Processes must name each other explicitly: send (P, message) – send a message to process P receive(Q, message) – receive a message from process Q Properties of communication link Links are established automatically A link is associated with exactly one pair of communicating processes Between each pair there exists exactly one link The link may be unidirectional, but is usually bi-directional

75 Indirect Communication Messages are directed and received from mailboxes (also referred to as ports) Each mailbox has a unique id Processes can communicate only if they share a mailbox Properties of communication link Link established only if processes share a common mailbox A link may be associated with many processes Each pair of processes may share several communication links Link may be unidirectional or bi-directional

76 Indirect Communication (cont.) Operations create a new mailbox send and receive messages through mailbox destroy a mailbox Primitives are defined as: send(A, message) – send a message to mailbox A receive(A, message) – receive a message from mailbox A

77 Indirect Communication (cont.) Mailbox sharing P 1, P 2, and P 3 share mailbox A P 1, sends; P 2 and P 3 receive Who gets the message? Solutions Allow a link to be associated with at most two processes Allow only one process at a time to execute a receive operation Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.

78 Synchronization Message passing may be either blocking or non- blocking Blocking is considered synchronous Blocking send has the sender block until the message is received Blocking receive has the receiver block until a message is available Non-blocking is considered asynchronous Non-blocking send has the sender send the message and continue Non-blocking receive has the receiver receive a valid message or null

79 Buffering Queue of messages attached to the link; implemented in one of three ways 1.Zero capacity – 0 messages Sender must wait for receiver (rendezvous) 2.Bounded capacity – finite length of n messages Sender must wait if link full 3.Unbounded capacity – infinite length Sender never waits

80 End of lecture 3 Thank you!