Hello. I will ask for help in solving the problem.
The task:
The parent process creates two children. Each of them prints its process ID, after which the parent process prints "Hello world". Used functions: fork (), wait (), exit ().
My code is:
pid_t p1, p2; int status1, status2; switch (p1 = fork()) { case -1: perror("Error fork"); return 1; case 0: printf("Child, pid=%d\n", getpid()); } switch (p2 = fork()) { case -1: perror("Error fork"); return 1; case 0: printf("Child, pid=%d\n", getpid()); } waitpid(p1, &status1, 0); waitpid(p2, &status2, 0); printf("Hello World"); At the exit:
- Child, pid = 5629
- Child, pid = 5630
- Hello WorldChild, pid = 5631
- Hello WorldHello WorldHello WorldPress to close this window ...
Point out the error please.