Professional Documents
Culture Documents
Process Management
• A program in execution
– We should know about processes by now.
• A process is an instance of a program running
• How does the OS correctly run multiple
processes concurrently?
– What kind of information to be kept?
– What does the OS have to do in order to run
processes correctly.
1
6/11/2014
• Early computers ran one process at a time • Method of operation in which multiple users
• A multiprogramming operating system is one with different programs interact nearly
that allows end-users to run more than one simultaneously with the central processing
program at a time. unit of a large-scale digital computer.
• Load several independent processes into
memory and switch the CPU from one job to
another when the first becomes blocked while
waiting for servicing by another device.
Process Scheduling
Pros and Cons
2
6/11/2014
• Long-term scheduler (or job scheduler) – • Parent process create children processes, which, in turn
create other processes, forming a tree of processes
selects which processes should be brought
into the ready queue • Generally, process identified and managed via a process
identifier (pid)
• Short-term scheduler (or CPU scheduler) –
• Resource sharing
selects which process should be executed next
– Parent and children share all resources
and allocates CPU – Children share subset of parent’s resources
– Sometimes the only scheduler in a system – Parent and child share no resources
• Execution
– Parent and children execute concurrently
– Parent waits until children terminate
16
After a fork, both parent and child keep running, and each can
fork off other processes.
A process tree results. The root of the tree is a special process
created by the OS during startup.
A process can choose to wait for
children to terminate. For
example, if C issued a wait()
system call, it would block until
G finished.
3
6/11/2014
Bootstrapping
Fork System Call
• When a computer is switched on or reset, there must • Current process split into 2 processes: parent, child
be an initial program that gets the system running
fork()
• This is the bootstrap program Returns -1 if unsuccessful
– Initialize CPU registers, device controllers, memory
– Load the OS into memory Returns 0 in the child Stack Stack
– Start the OS running
Returns the child’s
• OS starts the first process (such as “init”) identifier in the parent ret = 0
int main()
{
• getpid returns the identifier of the calling pid_t pid;
process. Example call (pid is an integer): int x = 1;
4
6/11/2014
Fork Example 3
Fork Example 2
• Key Points
– Both parent and child can continue forking void fork3() Bye
{ L2 Bye
printf("L0\n"); Bye
void fork2() Bye
{ fork(); L1 L2 Bye
L1 Bye
printf("L0\n"); printf("L1\n"); Bye
fork(); Bye L2 Bye
L0 L1 Bye
fork();
printf("L1\n"); Bye
fork(); printf("L2\n");
L0 L1 L2 Bye
printf("Bye\n"); fork();
} printf("Bye\n");
}
Summary
• Fork
– Creates a duplicate of the calling process
– The result is two processes: parent and child
– Both continue executing from the same point on
• Exit
– Orderly program termination
– Unblocks waiting parent
• Wait
– Used by parent
– Waits for child to finish execution