How to make parent process wait for child processes to finish?
问题 I have an assignment which gives me this code to transform into a code that makes the parent process wait for all children processes to finish. PS: the first code has 4 processes and needs to use waitpid to solve this. #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main(){ pid_t p = fork(); pid_t k = fork(); if(p>0){ printf("p=%d: PID = %d\n", p, getpid()); sleep(45); exit(0); } else if(p==0){ printf("p=%d: PID = %d\n", p, getpid()); exit(0); } else if(p