02 Processes
02 Processes
02 Processes
Processes
Matthew Dailey
Some material © Silberschatz, Galvin, and Gagne, 2002
Processes
What is a Process?
Text Section
Data Section
Execution Stack
Process State
Many processes,
potentially
Context switch:
Save current state to
PCB
Restore new state from
PCB
Can be slow (1-1000
usec)
Faster if hardware
provides support
Process Scheduling
Queues
Resources
serving the
queues
Schedulers
Long-term scheduler:
– Decides which jobs to admit to the system
– Controls the degree of multiprogramming
– Only used on batch systems
Short-term scheduler:
– Picks a READY process to run
– Executes frequently, e.g. every 0.1 sec
– Must be very fast to minimize system overhead
Medium-term scheduler:
– Selects processes to swap to disk to reduce degree of multiprogramming -> more
space for other processes
Swapping (Medium-Term Scheduler)
Process creation:
– Parent process calls create-process() system call.
– The new process is the child.
What happens when child is spawned?
– Parent continues to run concurrently, OR,
– Parent waits for children to terminate
What happens to child process memory?
– Can be a duplicate of the parent process memory, OR,
– Can have a different program loaded into it
Process Tree
Process Creation in Unix
Unbounded-buffer problem:
– Infinite buffer
– Consumer has to wait sometimes (buffer empty)
– Producer can always write to the buffer
Bounded-buffer problem:
– Finite buffer
– Consumer has to wait sometimes (buffer empty)
– Producer has to wait sometimes (buffer full)
Producer-Consumer Pattern
IPC
Producer-Consumer Pattern
Unbounded-buffer problem:
– Infinite buffer
– Consumer has to wait sometimes (buffer empty)
– Producer can always write to the buffer
Bounded-buffer problem:
– Finite buffer
– Consumer has to wait sometimes (buffer empty)
– Producer has to wait sometimes (buffer full)
Bounded-Buffer (Shared Memory) Solution
Client-side treats server request as a normal C (Java, Perl, etc.) function call.
On client side, a function stub traps to the kernel.
Kernel marshalls function arguments, transfers to server (probably via sockets)
Server unmarshalls function call, runs desired code and returns result to the
client.
Kernel on client side reconstructs the result as if the function was called locally
and returns control to the user process.
Very difficult for OS implementor, but very convenient for application
programmers.
What have we learned?
Introduction to processes
Basics of process management.
Process creation.
Introduction to local process cooperation via IPC
– Shared memory
– Message passing