RCS 205 Operating Systems Lecture 5: Introduction to Processes PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document provides a lecture on operating systems, focusing on the introduction to process management for a course called RCS 205. The lecture covers topics such as process states, implementation, and creation/termination.
Full Transcript
RCS 205 Operating Systems PART TWO: PROCESS MANAGEMENT: Lecture5: Introduction to Processes: Lecture 5: Scope: Introduction to processes. Process implementation. Operations on processes Goals: Define a process Examine how processes are implemented in...
RCS 205 Operating Systems PART TWO: PROCESS MANAGEMENT: Lecture5: Introduction to Processes: Lecture 5: Scope: Introduction to processes. Process implementation. Operations on processes Goals: Define a process Examine how processes are implemented in the computer system. Understand the role of the operating system in process management. 2 Introduction: A process can be thought of as a program in execution. A process will need certain resources to accomplish its tasks: such as CPU time, Memory, Files and I/O devices A process is the unit of work in most systems – such systems consist of a collection of processes: o/s processes – execute system code. User processes – execute user code. All these processes can potentially execute concurrently. 3 Introduction…2 Modern computers do multitasking While executing a program, a computer can also read from a disk and output text to a screen or a printer. CPU switches from one process to another At any one instance, the CPU runs only one program In the course of one second CPU may work on several programs, thus giving the users the illusion of parallelism (pseudo-parallelism). This is in contrast to h/w parallelism of multiprocessor systems 4 Introduction…3 A process is more than the program code: A program is a passive entity. A process is an active entity – with a program counter specifying the next instruction to execute and a set of associated resources. A process also includes: The current activity, as represented by the value of the program counter and the contents of the processor’s registers. The process stack containing temporary data, such as subroutine parameters, return addresses and temporary variables. A data section containing global variables. 5 Introduction…4 Two or more processes may be associated with the same program – however, these are considered as separate execution sequences. For example, several users may be running copies of the mail program, or the same user may invoke many copies of the same program. Each of these is a separate process and their data sections will vary. 6 Process states: As a process executes, it changes state. The state of a process is defined partly by the current activity of that process New – the process is being created. Running – instructions are being executed. Waiting – the process is waiting for some event to occur. Ready – the process is waiting to be assigned to the processor. Terminated – the process has finished execution. 7 Process states… Running Terminated 2 New 1 3 Blocked Ready 4 8 Introduction…process states: Transition 1 occurs when a process discovers that it cannot continue (can happen automatically or through system call) Note: Transitions 2 and 3 are caused by process scheduler, which is a part of the O/S. Transition 2 occurs when the scheduler decides that running process has had enough CPU time. Transition 3 occurs when other processes have had their share of the CPU and it is time for the first process to get the CPU again. Transition 4 occurs when the external event for which a process was waiting (for example, arrival of input) happens. 9 Process implementation: O/S maintains a process table or the Process Control Block (PCB) to implement, the process model with one entry per process. It contains information about the process’ state, including: Program counter, Stack pointer, Memory allocation, Status of its open files, Accounting information, etc. This is necessary when the process is switched from running to ready state so that it can be restarted later as if it had never been stopped. 10 Process implementation… Pointer Process state Process number (id) Program counter Registers Memory limits List of open files … 11 Process Implementation… 1. Process State – State may be ready, blocked or running. 2. Program counter – Counter indicates the address of the next instruction to be executed for this process. 3. CPU registers – Registers vary in number and type depending on the computer architecture. They include accumulators, index registers, stack pointers and general-purpose registers. 4. CPU scheduling information – includes a process priority, pointer to scheduling queues and any other scheduling parameters. 12 Process implementation… 5. Memory management information – includes the value of the base and limit registers, page tables or segment tables 6. Accounting information - includes the amount of CPU and real time used, account numbers, time limits, process numbers and so on. 7. I/O status information – includes the list of all I/O devices allocated to this process, list of open files etc 13 Operations on Processes: Operating Systems that support the process concept must provide some way to create all the processes needed. In some Operating Systems it is possible to have processes present when the system comes up. In other Operating Systems, some way is needed to create and destroy processes as the need arises. Processes need a way of creating other processes. Each process has one parent, but can have zero, or more children. 14 Process creation and termination: A process is an independent entity, though often it need to interact with other processes. One process may generate some output that another process would use as input. For example, in the shell command: cat chapter1 chapter2 chapter3 | grep tree The process, running cat, concatenates and outputs three files. Second process, grep, selects lines with the word ‘tree.’ Due to differences in speed grep may be ready to run, but no input. It must block until input is available. 15 Process Creation and Termination… Four Principal events that cause process creation are: System initialization Execution of a process creation system User request to create a new process Initiation of a batch job 16 Process Creation and Termination… Four Conditions that lead to process termination: Normal exit (voluntary) Error exit (voluntary) Fatal error (involuntary) Killed by another process (involuntary) 17 Next lecture: Process scheduling. Cooperating processes. Threads. IPC. 18