In: Computer Science
Write a C program (using Code::blocks) 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> #include <unistd.h> #include <sys/wait.h> int main() { // here only main process executes. No childs // get pid of main printf("%10s%10s%10s%10s\n", "Child", "PID", "PPID", "X"); int x =0; for (int i = 0; i < 10; i++) { if(fork() == 0) { printf("%10d%10d%10d%10d\n", i, getpid(), getppid(), 5 * (i+1)); return 0; } } for (int i = 0; i < 10; i++) { wait(NULL); } return 0; }
*************************
let me know if any issues.