#include <stdio.h>
#include <unistd.h> int main()
{
/* fork a child process */ fork(); /* fork another child process */ fork(); /* and fork another */ fork(); return 0;
}
Figure 3.31 How many processes are created?
Sol: To know how many processes are created we modified the program using getpid() and printf(). Please find the modified program below
#include <stdio.h>
#include <unistd.h> int main()
{
pid_t pid;
/* fork a child process */ fork(); /* fork another child process */ fork(); /* and fork another */ fork(); pid = getpid(); printf("Process : pid = %d \n",pid); return 0;
}
Output : Number of process = 8.
3.8 Describe the differences among short-term, medium-term, and longterm scheduling. Sol:
Scheduler : A process moves among different scheduling queues throughout its lifetime. Operating system takes care of selecting the processes from these queues in some fashion. Selecting process is done by the the appropriate scheduler.
Types of scheduling:
Short - term (or) CPU Scheduler
Medium – term
Long – term (or) Job Scheduler
Short – Term Scheduler: Short term scheduler selects the processes that are ready to execute and allocates CPU to one of them.
Medium – Term Scheduler: Medium term scheduler is introduced by some operating systems such as time sharing systems. Medium term scheduler can remove a process from the memory and decrease the degree of multiprogramming and the same process can be later reintroduced into the memory and its execution can be started where it was stopped.
Long – Term Scheduler: Some processes are submitted than can be executed and these processes are pooled into the mass storage device. Long term scheduler selects processes from these pool and loads them into the memory for execution.
3.14 Using the program in Figure 3.34, identify the values of pid