OS Module2.1 Process Management
OS Module2.1 Process Management
Process Scheduling
Operations on Processes
Interprocess Communication
To introduce the notion of a process -- a program in
execution, which forms the basis of all computation.
Process
o A process is a program under execution.
o process execution must progress in sequential fashion.
Program counter
CPU registers
Memory-management information
Accounting information
• Maximize CPU use, quickly switch processes onto CPU for time
sharing.
•Rectangle represents
a queue.
Short-Term Scheduler
Medium-Term Scheduler
Long-term scheduler(or job scheduler) – selects jobs from
the job pool (of secondary memory, disk) and loads them into
the memory.
When system loads get high, this scheduler will swap one or
more processes out of the ready queue for a few seconds, in
order to allow smaller faster jobs to finish up quickly and clear
the system.
Advantages of medium-term scheduler –
• process creation.
• process preemption.
• process blocking.
• process termination.
Parent process create children processes, which, in turn create
other processes, forming a tree of processes.
• System initialization.
Resource sharing
◦ Parent and children share all resources.
◦ Children share subset of parent’s resources.
◦ Parent and child share no resources.
Execution
◦ Parent and children execute concurrently.
◦ Parent waits until children terminate.
Address space
◦ Child duplicate of parent.
◦ Child has a new program loaded into it.
UNIX examples
◦ fork system call creates new process.
◦ exec system call used after a fork to replace the process’
memory space with a new program.
#include <sys/types.h>
#include <studio.h>
#include <unistd.h>
int main()
{
pid_t pid;
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child */
wait (NULL);
printf ("Child Complete");
}
return 0;
}
Process Preemption
An interrupt mechanism is used in preemption that suspends the
process executing currently and the next process to execute is
determined by the short-term scheduler.
Preemption makes sure that all processes get some CPU time for
execution.
This event may be I/O as the I/O events are executed in the
main memory and don't require the processor. After the event is
complete, the process again goes to the ready state.
• Message passing
Mechanism for processes to communicate and to synchronize their
actions.