I am creating a parent process, than an intermediate process and another child, and a child of intermediate process using fork() in C. Now I and trying to print the processes using ps -f --ppid ..,.. but some of the child processes finish hence it won't be printed when ps is ran using system(). How do I use wait and waitpid() so my parent will wait until child finishes it's process.
Current O/p:
UID PID PPID C STIME TTY TIME CMD
pc 24400 306 0 15:48 pts/2 00:00:00 ./a
pc 24401 24400 0 15:48 pts/2 00:00:00 [a]
pc 24404 24400 0 15:48 pts/2 00:00:00 sh -c ps -f --ppid 306,24400,24401,24402
Expected O/p:
UID PID PPID C STIME TTY TIME CMD
pc 24400 306 0 15:48 pts/2 00:00:00 ./a
pc 24401 24400 0 15:48 pts/2 00:00:00 ./a
pc 24402 24400 0 15:48 pts/2 00:00:00 ./a
pc 24403 24401 0 15:48 pts/2 00:00:00 ./a
pc 24404 24400 0 15:48 pts/2 00:00:00 sh -c ps -f --ppid 306,24400,24401,24402.
Thanks in advance!