Introduction to Processes in Computer Systems SEEM 3460 1
Overview of Processes What is the concept of a process A program in execution The animated spirit of a program The entity that can be assigned to and executed on a processor The life of a process is bounded by its creation and termination. All multiprogramming operating systems, which can support thousands of users, are built around the concept of the process. Most requirements that the operating system must meet can be expressed with reference to processes SEEM 3460 2
Overview of Processes The operating system must interleave the execution of several processes to maximize processor utilization while providing reasonable response time. The operating system must allocate resources to processes in conformance with a specific policy while at the same time avoiding deadlock The operating system is required to support inter-process communication and user creation of processes, both of which may aid in the structuring of applications. SEEM 3460 3
Trace of a Process We can characterize the behavior of an individual process by listing the sequence of instructions that execute for that process. Such a listing is referred to as a trace of the process. SEEM 3460 4
Trace of a Process (cont d) c SEEM 3460 5
SEEM 3460 6
A Two-State Process Model A process model is used to describe the behavior what we want the processes to exhibit. Two-State Process Model SEEM 3460 7
A Two-State Process Model (cont d) Each process must be represented in some way so that OS can keep track of it. current state location in memory Each queue item may be: a pointer to a particular process a data block representing a process Process creation (Process Spawning): OS may create a process by itself e.g. a user logs on to the system OS may create a process on behalf of an application e.g. requests a file to be printed Application may create process e.g. a Web browser creates a process to download a file Process termination: Termination request by application, error and fault conditions. SEEM 3460 8
A Five-State Process Model The 2-state model does not consider that some processes in the queue may not be ready to execute e.g. waiting for I/O, blocked SEEM 3460 9
A Five-State Process Model (cont d) Running: The process is currently being executed Ready: The process is prepared to execute when given the opportunity Blocked: The process cannot execute until some event (e.g. I/O read/write) occurs New: The process has just been created but has not yet been admitted to the pool of executable processes by the OS. Exit: The process has been released from the pool of executable processes by the OS. SEEM 3460 10
SEEM 3460 11
A Five-State Process Model (cont d) Queuing Model SEEM 3460 12
Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O All processes in all queues must be resident in main memory. However, the main memory size has limit. To accommodate more processes: Expand main memory to accommodate more processes. (But this method is not good) Swapping (moving part of all of a blocked process from main memory to disk the process is suspended). Virtual memory reserving some disk storage to be used as memory for the processes. SEEM 3460 13
Swapping Swap blocked processes to disk to free up more memory Blocked state becomes suspend state when swapped to disk SEEM 3460 14
One Suspend State SEEM 3460 15
Processes and Resources SEEM 3460 16
OS Functions OS controls events within the computer system. Main functions of OS: schedules and dispatches processes for execution by the processor allocates resources to processes responds to requests by user programs for basic services. OS manages the use of system resources by processes SEEM 3460 17
OS Control Tables OS must have information about the current status of each process and resource. OS constructs and maintains tables of information about each process that it is managing. Memory tables: used to keep track of both main(real) and secondary(virtual) memory. Some of main memory is reserved for use by OS I/O tables: used to manage the I/O devices and channels of the computer system File tables: provided information about the existence of files, their location on secondary memory, their current status, etc. Process tables SEEM 3460 18
Process Table Information about where process is located Physical manifestation of a process including A set of programs to be executed A set of data (e.g., local variables, global variables) Process Control Block information contains the collection of attributes sufficient information so that it is possible to interrupt a running process and later resume execution some examples of information: program counter, register content) Process Image refers to all of the above information SEEM 3460 19
SEEM 3460 20
Process Creation Assign a unique process identifier to the new process. At this time, a new entry is added to the primary process table Allocate space for the process including the space for process control block The process control block must be initialized. Put the process into the Ready queue. SEEM 3460 21
Change of Process State If the current running process is to be moved to another state, then the operating system must make substantial changes in its environment. 1. Save the context of the processor, including program counter and other registers 2. Update the process control block of the process that is currently in the Running state 3. Move the process control block of this process to the appropriate queue 4. Select another process for execution 5. Update the process control block of the process selected 6. Update memory-management data structures 7. Restore the context of the processor to that which existed at the time the selected process was last switched out of the Running state, by loading in the previous values of the program counter and other registers. SEEM 3460 22