Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually...

16
Chapter 4 Chapter 4 Processes Processes

Transcript of Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually...

Page 1: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Chapter 4Chapter 4

ProcessesProcesses

Page 2: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Process: what is it?Process: what is it?

A program in executionA program in execution usuallyusually

Can also have suspended or waiting Can also have suspended or waiting processesprocesses

Page 3: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Memory Management Memory Management IssuesIssues

Each process needs its own avail Each process needs its own avail pointerpointer

Heap needs to be setup when Heap needs to be setup when process is createdprocess is created

Page 4: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Process StatesProcess States

NewNew RunningRunning WaitingWaiting Ready (Suspended)Ready (Suspended) TerminatedTerminated

Page 5: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Process State DiagramProcess State Diagram

new

ready running

waiting

terminatedadmitted exit

interrupt

scheduler dispatch

IO or event completion IO or wait event

Page 6: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Process Control BlockProcess Control Block

pointer processstate

process number

program counter

registers

memory limits

list of open files...

Page 7: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Process Control BlockProcess Control Block Process stateProcess state

ready, running, waiting …ready, running, waiting … Program counterProgram counter

next instruction to be executednext instruction to be executed CPU registersCPU registers

process context (what am I working on)process context (what am I working on) Scheduling InformationScheduling Information

priority, pointers to scheduling queues …priority, pointers to scheduling queues … Memory-management infoMemory-management info

base and limit registers, page tables, segment tablesbase and limit registers, page tables, segment tables IO status informationIO status information

open files, I/O devices open to this process …open files, I/O devices open to this process …

Page 8: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Loading a ProcessLoading a Process

Find Process on DiskFind Process on Disk Get size of processGet size of process Add PCB to process tableAdd PCB to process table Allocate memoryAllocate memory Assign memory to processAssign memory to process Assign stack space, and heapAssign stack space, and heap set up the bounds registersset up the bounds registers put process in memoryput process in memory

Page 9: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Buffering a FileBuffering a File

bufferFile Vector Address: 0x1C

Registers Used: r0, r1Input Parameters:

r1 &filenameReturned Value(s):

r0 failed = 0 succeeded = 1r1 size of coder2 size of data

Operation(s):

Page 10: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Load FileLoad File

Vector Address:Vector Address: 0x1D0x1DRegisters Used:Registers Used: r0, r1r0, r1Precondition: File is in bufferPrecondition: File is in buffer

Input Parameters:Input Parameters:r0 r0 code address code addressr1 r1 data address data address

Returned Value(s):Returned Value(s):r0 r0 failed = 0 succeeded = 1failed = 0 succeeded = 1r1 r1

Page 11: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Running a ProcessRunning a Process

Set up stackSet up stack Set the process state to runSet the process state to run Change program counter to process Change program counter to process

beginbegin

Other issues??Other issues??

Page 12: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Terminating a processTerminating a process

hlt?? vs interrupt 20hlt?? vs interrupt 20 Context switch to OSContext switch to OS Disable interruptsDisable interrupts Set process status to terminatedSet process status to terminated de-allocate memoryde-allocate memory clean up resourcesclean up resources remove pcb from process tableremove pcb from process table Enable interruptsEnable interrupts

Page 13: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Suspending a processSuspending a process

disable interruptsdisable interrupts save process contextsave process context set process status to suspendedset process status to suspended enable interruptsenable interrupts

Page 14: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

System CommandsSystem Commands

dirdir make a system callmake a system callcwdcwd make a system callmake a system callloadload load a file into memoryload a file into memoryrunrun run a process run a process psps print out the processes in memoryprint out the processes in memoryhelphelp just print out the helpjust print out the helpexitexit make a system callmake a system call

memmem Show the contents of memory (system)Show the contents of memory (system)freefree Show the amount of free memory (system)Show the amount of free memory (system)

Page 15: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Running the ShellRunning the Shell

In shell processIn shell process get command stringget command string parse commandparse command switch on commandswitch on command

Set up command parametersSet up command parameters Execute commandExecute command

get next commandget next command

Page 16: Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.

Executing a commandExecuting a command

Two optionsTwo options Do the command in the shellDo the command in the shell Spawn a new processSpawn a new process

Which one is better??Which one is better??