process concept - florida atlantic universitytami/cop4610m3slides.pdfprocess concept process –an...

21
Operating systems Module 3 Process Concept PART I 1 Tami Sorgente

Upload: others

Post on 20-May-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

Operating systemsModule 3

Process Concept

PART I

1Tami Sorgente

Page 2: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

MODULE 3 – PROCESS CONCEPT

Process definition

PCB

Process states

2Tami Sorgente

Page 3: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESSES

Process Concept

o Program in execution

o Active program

3Tami Sorgente

Page 4: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS CONCEPT

Process – An active program; process

execution must progress in sequential

fashion The program code, also called text section

Current activity including program counter, processor

registers

Stack containing temporary data

Function parameters, return addresses, local variables

Data section containing global variables

Heap containing memory dynamically allocated during run

time

4Tami Sorgente

Page 5: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS CONCEPT

Program is passive entity stored on disk

(executable file), process is active Program becomes process when executable file loaded into

memory

Process Control Block (PCB) A data structure created by the OS for each process

One program can be several processes

5Tami Sorgente

Page 6: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS CONTROL BLOCK (PCB)Process state –

o running, waiting, etc

Program counter –

o location of instruction to next execute

CPU registers –

o contents of all process-centric registers

CPU scheduling information-

o priorities, scheduling queue pointers

Memory-management information –

o memory allocated to the process

Accounting information –

o CPU used, clock time elapsed since start, time limits

I/O status information –

o I/O devices allocated to process, list of open files

6Tami Sorgente

Page 7: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS STATES

As a process executes, it changes state

o new: The process is being created

o ready: The process is waiting to be assigned

to a processor

o running: Instructions are being executed

o waiting: The process is waiting for some

event to occur

o terminated: The process has finished

execution

7Tami Sorgente

Page 8: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS STATES

8

New

Ready

Running

TerminatedBlocked

admitted

dispatchexit

interrupt

I/O or event

I/O or event

completion

Tami Sorgente

Page 9: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

Operating systemsModule 3

Processes

PART II

9Tami Sorgente

Page 10: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

UNIT 3 – PROCESS CONCEPT

System schedulers

Operations on processes

10Tami Sorgente

Page 11: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS SCHEDULING

Maximize CPU use, quickly switch processes

onto CPU for time sharing

System queues:

o Job queue – set of all processes in the system

o Ready queue – set of all processes residing in

main memory, ready and waiting to execute

o Device queues – set of processes waiting for

an I/O device

Processes migrate among the various queues

11Tami Sorgente

Page 12: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

SCHEDULERS

Long-term scheduler (or job scheduler) o Selects which processes should be brought into the

ready queue - invoked infrequently

Short-term scheduler (or CPU scheduler)o Selects which process should be executed next and

allocates CPU- invoked very frequently (must be fast)

o Sometimes the only scheduler in a system

Medium-term scheduler can be added o Remove process from memory, store on disk, bring

back in from disk to continue execution: swapping

12Tami Sorgente

Page 13: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS DEFINITION

Processes can be described as either type:

o I/O-bound process – spends more time doing

I/O than computations, many short CPU bursts

o CPU-bound process – spends more time

doing computations; few very long CPU bursts

Long-term scheduler strives for good

process mix

The long-term and medium term scheduler

control the degree of multiprogramming

(number and type of active programs)

13Tami Sorgente

Page 14: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

MEDIUM TERM SCHEDULING (SWAPPING)

14

New

Ready

Running

TerminatedBlocked

admitted

dispatch

exit

interrupt

I/O or event

I/O or event

completion

Ready

swapped

Blocked

&

swapped

admitted

swapped

swapped

I/O or event

completionSwapped out

Tami Sorgente

Page 15: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

CONTEXT SWITCH

When CPU switches to another processo save the state of the old process and

o load the saved state for the new process via a context switch

Context of a process represented in the PCB

Context-switch time is overheado The system does no useful work while switching

o The more complex the OS and the PCB

Longer the context switch

Time dependent on hardware support

o Some hardware provides multiple sets of registers per CPU -> multiple contexts loaded at once

15Tami Sorgente

Page 16: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

OPERATIONS ON PROCESSES

Creation

Termination

Block (synchronization – Unit 8)

Wake up (synchronization – Unit 8)

Change priority (CPU scheduling – Unit 5)

Dispatch

16Tami Sorgente

Page 17: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS CREATION

o Parent process creates children processes, which, in turn create other processes, forming a tree of processes

o Generally, process identified and managed via aprocess identifier (pid)

o Resource sharing options Parent and children share all resources

Children share subset of parent’s resources

Parent and child share no resources

o Execution options Parent and children execute concurrently

Parent waits until children terminate

17Tami Sorgente

Page 18: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

A TREE OF PROCESSES IN LINUX

18

init

pid = 1

sshd

pid = 3028

login

pid = 8415kthreadd

pid = 2

sshd

pid = 3610

pdflush

pid = 200

khelper

pid = 6

tcsch

pid = 4005emacs

pid = 9204

bash

pid = 8416

ps

pid = 9298

Tami Sorgente

Page 19: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS TERMINATION

Voluntary

o Normal exit

o Internal error or exception Example: exit if no input file is found

Involuntary

o Fatal error Example: divide by zero/ illegal memory access

o Explicitly killed by another process Example: task manager

19Tami Sorgente

Page 20: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

PROCESS TERMINATION

Process terminationo Process executes last statement and asks the operating

system to delete it

o Output data from child to parent

o Process’ resources are deallocated by operating system

o Parent may terminate execution of children processes Child has exceeded allocated resources

Task assigned to child is no longer required

If parent is exiting Some operating systems do not allow child to continue if its parent terminates

All children terminated - cascading termination

o If no parent waiting, then terminated process is a zombie

o If parent terminated, processes are orphans

20Tami Sorgente

Page 21: Process Concept - Florida Atlantic Universitytami/COP4610M3Slides.pdfPROCESS CONCEPT Process –An active program; process execution must progress in sequential fashion The program

INTERPROCESS COMMUNICATION

Processes within a system may be independent or cooperating

Cooperating process can affect or be affected by other processes, including sharing data

Reasons for cooperating processes:

o Information sharing

o Computation speedup

o Modularity

o Convenience

Cooperating processes need

interprocess communication (IPC)

Two models of IPC (more details in Unit 7)

o Shared memory

o Message passing

21Tami Sorgente