Write a C program that outputs a formatted header line and creates 10 children processes each of which displays a line of the output as shown below. Notice the values of Child no and x, they have to be the same as shown here while the processes PIDs values are based on the what your system assigns to these processes.
Child
PID
PPID X
0
13654 13653 5
1
13655 13653 10
2
13656 13653 15
3
13657 13653 20
4
13658 13653 25
5
13659 13653 30
6 13660
13653 35
7
13661 13653 40
8
13662 13653 45
9
13663 13653 50
#include<stdio.h>
int main()
{
int pid,ppid,x,i,k;
x=5;
for(i=0;i<10;i++)
{
// k=fork();
if(fork() == 0) // fork will give the child process
{
printf("%d %d %d %d\n",i,getpid(),getppid(),x); //it will print pid
and ppid
exit(0);
}
for(int i=0;i<10;i++) // loop will run n times (n=5)
wait(NULL);
x=x+5;
}
return 0;
}
OUTPUT :
Get Answers For Free
Most questions answered within 1 hours.