Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)

Similar presentations

Presentation on theme: "Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)"— Presentation transcript:

1 Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)

2 © De Montfort University, 2004CSCI2413 - L32 Lecture Outline Concept of a “Process” Process Creation/Termination Process states Process Control Block (PCB) An overview of process scheduling –concepts –problems

3 © De Montfort University, 2004CSCI2413 - L33 Concept of a “Process” Recall –a process is an instance of a program that is being executed a program which is loaded into memory and is running A process must execute in sequential fashion –even though it may be interrupted by the operating system so that other processes may run

4 © De Montfort University, 2004CSCI2413 - L34 Process Creation Parent process creates child processes which, in turn, can create others to form a process ‘tree’ Options for process creation –resource sharing options parent and children share all resources children share subset of parent’s resources parent and child share no resources –execution options parent and children execute concurrently parent waits until children terminate

5 © De Montfort University, 2004CSCI2413 - L35 Process Termination Normal termination occurs if the process reaches its final instruction, execute exit A parent process may terminate execution of its child process (abort) –this may be because the child has exceeded a resource limit the user requests a child to terminate (because it’s stuck) the parent process is itself being terminated

6 © De Montfort University, 2004CSCI2413 - L36 Process States As a process executes, it changes state new the process is being created running instructions are being executed ready the process is ready to run, but is waiting for the processor to become available blocked (waiting) the process is waiting for some event to occur terminated the process has finished execution

7 © De Montfort University, 2004CSCI2413 - L37 Process State Diagram ready running scheduler dispatch interrupt blocked I/O or event block I/O or event completion new admitted terminated exit

8 © De Montfort University, 2004CSCI2413 - L38 Process Information OS must hold info. about a process so that it can change its state Typical information held –process management process state, program counter, processor registers, time process started, process id, parent id –memory management code location and size, data location and size, stack –I/O management files open and modes, I/O devices in use, current directory

9 © De Montfort University, 2004CSCI2413 - L39 Process Control Block (PCB) OS holds info. for each process in PCB (also referred to as, process table) –one entry per process When a process starts, OS allocates an entry in its PCB –the process runs until it is interrupted OS updates the process info. –or makes a system call (e.g. to open a file) OS performs the system call and updates the process info.

10 © De Montfort University, 2004CSCI2413 - L310 Process Control Block Process Number (ID) Process state Priority Program Counter Memory Pointers I/o states information Registers Accounting Information. To distinguish it from other processes Executing, running etc. Priority level Hold address of next instr. Hold base address of code or data I/O states and requests Time limits, account numbers

11 © De Montfort University, 2004CSCI2413 - L311 Context Switch When processor switches to another process, OS saves the state of the old process and load the saved state for the new process This is called a context switch –the time spent doing this is overhead (idle) –the system does no useful work while switching This time depends on both the OS and the hardware support

12 © De Montfort University, 2004CSCI2413 - L312 CPU Switch From Process to Process

13 © De Montfort University, 2004CSCI2413 - L313 Scheduling Concepts Suppose there are two jobs in the process table, both of which are in the ready state –which one should the operating system return to the ‘running’ state? –suppose one job requested a disk I/O operation and one process was doing a lengthy calculation using a lot of processor time, and was interrupted does that alter the choice? The operating system has to make a choice –there are different factors that affect the choice –there are different algorithms to make the selection

14 © De Montfort University, 2004CSCI2413 - L314 Scheduling Types There are different classes of scheduler types –long term selects which processes should be brought into the queue –short term selects which process should be executed by the processor –medium term selects which process is temporarily suspended and swapped out of main memory to reduce the number of processes occupying memory –not used in all operating systems

15 © De Montfort University, 2004CSCI2413 - L315 Scheduling Queues I/O waiting queue I/O ready queue CPU the short term scheduler decides which process to allocate to the CPU the long term scheduler decides which processes can join the ready queue partially executed swapped-out processes a medium term scheduler decides which processes to swap out of main queue

16 © De Montfort University, 2004CSCI2413 - L316 Potential Problems Imagine an operating system has a print spooler –when a process wants to print a file it enters the file name in a special spool directory –another process (the spooler demon) periodically checks to see if there are any files to be printed –the operating system maintains two variables out: holds the number of the next file to be printed in: holds the number of the next free slot Now imagine two processes trying to print a file at the same time –each needs to submit the file name to the spool queue This create a ‘RACE’ condition (more about this later)

17 © De Montfort University, 2004CSCI2413 - L317 Summary The process model – Process Creation/Termination –process states Process implementation –process control block An overview of process scheduling –concepts –Problems (Race condition, more in later lectures)

Download ppt "Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)"

Similar presentations

Ads by Google