Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually...
-
Upload
christine-strickland -
Category
Documents
-
view
215 -
download
1
Transcript of Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually...
Chapter 4Chapter 4
ProcessesProcesses
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
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
Process StatesProcess States
NewNew RunningRunning WaitingWaiting Ready (Suspended)Ready (Suspended) TerminatedTerminated
Process State DiagramProcess State Diagram
new
ready running
waiting
terminatedadmitted exit
interrupt
scheduler dispatch
IO or event completion IO or wait event
Process Control BlockProcess Control Block
pointer processstate
process number
program counter
registers
memory limits
list of open files...
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 …
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
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):
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
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??
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
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
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)
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
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??