Create a fan of processes and chain of processes. Ask the user for the number of processes to be created.

CODE: (i) CHAIN PROCESS
#include <stdio.h>
#include<unistd.h>
void main()
{
  pid_t cid=0;
int n,i,a=5,j;
printf("enter numbers of Processes");
scanf("%d",&n);
for(i=0;i<n;i++)
{
 cid=fork();
 if(cid!=0)
 {
   printf("%d Process id:%d Child:%d\n",i,getpid(),cid);
   break;
 }
}
}

OUTPUT:

(ii) FAN PROCESS
#include <stdio.h>
#include<unistd.h>
void main()
{
  pid_t cid=0;
int n,i,a=5,j;
printf("enter numbers of Processes");
scanf("%d",&n);
for(i=0;i<n;i++)
{
 cid=fork();
 if(cid!=0)
 {
   printf("%d Process id:%d Child:%d\n",i,getpid(),cid);
 }
 else
    break;
}
}
OUTPUT:





No comments:

How to crack Aptitude Question In GATE and many Competitive Examination

As you know the aptitude in the competitive examination is quite for more challenging to clear it. But believe me it is the easy stuff t...