chapter 3: processescontents.kocw.net/kocw/document/2014/yeungnam/kwakjongwo… · accounting...

20
Chapter 3: Processes Chapter 3: Processes

Upload: others

Post on 15-Aug-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Chapter 3: ProcessesChapter 3: Processes

Page 2: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Process ConceptProcess Concept

An operating system executes a variety of programs:Batch systemBatch systemInteractive System, i.e., Time-shared systems

Textbook uses the terms job and process almost interchangeablyProcess – a program in executionp g

the unit of resource allocationthe unit of dispatchingprocess execution progresses in sequential fashionone copy of explore program vs. several execution instances of explore

c.f., spell checker in word program thread conceptAfter the introduction of thread concept, process indicates the unit of resource allocation, instead of the unit of dispatching. Actually, the unit of dispatching is thread

A process includes:Program and data section for process image Stack and heap section for memory management

3.2 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Other meta data

Page 3: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Process Image in MemoryProcess Image in Memory

Process is

PCB in Kernel Space

+

Process image itself shown

1) In case of Kernel Mode

ti dd ibl: entire address spaces are accessible

2) In case of User Mode

: only user address spaces are accessible: only user address spaces are accessible

e.g., In linux kernel 2.4, 0~4G is addressable in kernel mode but 0~3G is addressable in user mode.

3.3 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 4: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Process Image in MemoryProcess Image in Memory

# include <stdio.h>

i t l b 3 // l b l t ti i blint glob=3; //global or static variable

Function_A (void)

{ i t l *d i{ int loc, *dynamic;

dynamic = malloc(1383);

printf(“….

return 0;return 0;

}

Some parts of data is called bss (block started by symbol) which contains

3.4 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Some parts of data is called bss (block started by symbol), which contains uninitialized global variable or uninitialized static variable.

Page 5: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Process StateProcess State

As a process executes, it changes state

new: The process is being created.

running: Instructions are being executed.

waiting: The process is waiting for some event to occur.I/O operation, Message send/receive handling, etc.

ready: The process is waiting to be assigned to a processor.

terminated: The process has finished execution.

3.5 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 6: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Diagram of Process StateDiagram of Process State

3.6 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 7: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Diagram of Process StateDiagram of Process State

3.7 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 8: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Process State Example in UnixProcess State Example in Unix

By kernel or user request

3.8 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 9: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Process Control Block (PCB)Process Control Block (PCB)

Information associated with each processProcess stateProgram counterCPU registersCPU registersCPU scheduling informationMemory-management informationy gAccounting informationI/O status information

3.9 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 10: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Process Control Block (PCB)Process Control Block (PCB)

3.10 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 11: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Process Control Block (PCB)Process Control Block (PCB)

3.11 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 12: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

CPU Switch From Process to ProcessCPU Switch From Process to Process

3.12 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 13: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

CPU Switch From Process to ProcessCPU Switch From Process to Process

3.13 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 14: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Advanced TopicAdvanced Topic

PCB in UNIXPCB in UNIX

Page 15: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

PCBPCB(Process Control Block)(Process Control Block)

PID (P Id tifi )PID (Process Identifier)PriorityWaiting EventStateLocation of image in diskLocation of image in memoryLocation of image in memoryopen filesdirectorystate vector save areattyparent, child processp , pexecution time, ....

3.15 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 16: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

ObservationObservationObservationObservation

# ttys/system a lot y y# processes/tty (*1) of spacesize of PCB/process (*2) for PCB’s

most processes interact with humanidl ( d t) t f tiprocesses idle (swapped out) most of time

Any method to make low overhead state while swapped out ?

(*1) eg (sh, mail, ed, ....) => (50 tty), (3 process / tty) => 150 processes

3.16 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

( ) g ( ) ( y) ( p y) p(*2) Kilo Bytes per PCB. Memory was expensive in 70’s

Page 17: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

ObservationObservation

UNIX is multi user system

ObservationObservation

UNIX is multi-user systemMany processes are executed concurrentlyLarge space needed for PCBg p

Most UNIX processes interact with humanProcesses idle most of time Processor is accordingly idle as well

(99.9% of time idle)Swap out them while idleSwap out them while idleSave memory space

Why not swap out the PCB too?

3.17 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 18: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Per Process DataPer Process Data

This part shouldPID premain in memory

even if the rest is swapped out to disk with process image

PriorityWaiting Event State to disk with process image

Otherwise, you cannot swap in laterLocation of image in disk

Location of image in memoryg yopen filesdirectorystate vector save area Divide PCB into 2 partsstate vector save areattyparent, child processexecution time, ....

Divide PCB into 2 parts(1) struct proc

---- always in memoryexecution time, ....

(2) struct userd t

3.18 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

---- swapped out

Page 19: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Per Process DataPer Process Data

PID PriorityWaiting Event

( f b )StateLocation of image in diskLocation of image in memory

struct proc (a few bytes)

open filesdirectorystate vector save areattyparent, child processexecution time, .... struct user (LARGE !)

3.19 Silberschatz, Galvin and Gagne ©2009Operating System Concepts

Page 20: Chapter 3: Processescontents.kocw.net/KOCW/document/2014/Yeungnam/KWAKJongwo… · Accounting information ... Advanced Topic PCB in UNIX. PCB (Process Control Block) PID (P Id tifi

Per Process Data Per Process Data

struct procstruct procone per process memory resident part (never swapped out, always in memory)

PID state priority- PID - state, priority- waiting event - location of image in disk

data needed even when process is not active

t tstruct userdata needed only when process is activecalled “u block”always addressed by virtual address, because u block resides in disk

since only one process is active on CPU at a time

d % dl N k Most processes spend 99.9% time idle --> UNIX keeps

only proc (few bytes) in core --> very low overhead

3.20 Silberschatz, Galvin and Gagne ©2009Operating System Concepts