Академический Документы
Профессиональный Документы
Культура Документы
Process Management
Today: processes and process management
CS 537
Lecture 3: Processes
Michael Swift
9/15/09
User Apps
Example OS in operation
Firefox
Photoshop
Acrobat
Acrobat
Operating System
Device
Drivers
Process
Manager
Interrupt
Handlers
Network
Support
Portable
Memory
Manager
9/15/09
Boot &
Init
nfsd
ls
nfsdemacs
gcc
OS
lswww
lpr
www emacs
OS
lpr
How to speed-up?
Overlap I/O bursts of one process with CPU bursts of another
9/15/09
9/15/09
9/15/09
The Process
What is a program?
A program consists of:
9/15/09
9/15/09
Preparing a Program
compiler/
assembler
source
file
The loader:
reads and interprets the executable file
.o files
static libraries
(libc, streams)
Code
Initialized data
BSS
Running a program
Linker
Header
Executable file
(must follow standard format,
such as ELF on Linux,
Microsoft PE on Windows)
Symbol table
Line numbers
Ext. refs
9/15/09
9/15/09
9/15/09
Whats in a Process?
Process != Program
DLLs
Program is passive
Code + data
Header
an address space
the code for the running program
the data for the running program
an execution stack and stack pointer (SP)
mapped segments
Code
Initialized data
SP
Stack
Process
Example:
address space
We both run IE:
- Same program
- Separate processes
Symbol table
Line numbers
Ext. refs
BSS
Executable
Initialized data
just an integer
9/15/09
Heap
9/15/09
Process states
PC
Code10
New
create
Ready
I/O
done
unschedule
Terminated
kill
Waiting
schedule
Running
I/O,
page fault, etc.
9/15/09
9/15/09
12
9/15/09
PCB
13
14
process number
program counter
stack pointer
username of owner
queue pointers for state queues
accounting info
process state
9/15/09
process ID (PID)
execution state
program counter, stack pointer, registers
memory management info
UNIX username of owner
scheduling priority
accounting info
pointers into state queues
In linux:
15
9/15/09
16
9/15/09
Implicit:
Opportunity cost of flushing useful caches (cache, TLB, etc.)
Wait for pipeline to drain in pipelined processors
9/15/09
State queues
18
State queues
Ready queue header
head ptr
tail ptr
netscape pcb
emacs pcb
cat pcb
netscape pcb
ls pcb
19
20
9/15/09
9/15/09
Process creation
9/15/09
22
23
9/15/09
24
9/15/09
fork( )
output
9/15/09
25
9/15/09
exec()
stops the current process
loads program prog into the address space
initializes hardware context, args for new program
places PCB onto ready queue
note: does not create a new process!
26
UNIX shells
27
9/15/09
28
9/15/09
Which is better?
Which is better?
More flexible?
Easier?
Faster?
9/15/09
Windows
Unix
29
9/15/09
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
si.cb = sizeof(si);
if( !CreateProcess(
NULL,
"c:\\myprog.exe 1 2",
NULL,
NULL,
FALSE,
0, NULL,
NULL,
&si,
&pi ) )
{
printf( "CreateProcess failed
(%d).\n", GetLastError() );
return;
}
30
Process Termination
9/15/09
31