In my code, the parent process does not need to wait these children processes. And I need to know which child process finishes first to do rest of the code.

Recommended Answers

All 3 Replies

If the parent process doesn't have to wait, why does it care who finishes first.

If at least one child process needs to finish, then you have to wait.

In my code, the parent process does not need to wait these children processes. And I need to know which child process finishes first to do rest of the code.

In the parent process u already have the child process id's.
U can repeatedly use the 'ps' command to ckeck which processes are running. Whenever u get one process missing break the loop and continue. And now u have the process id which just finished.

I dont know how to check the status of the processes in other way (there must be some).
u can do

system("ps>processes");
//this will store the output to the file 'processes'
//parse from the file whatever u need.

Hope thats of some help

also check the manual of the function

waitpid(.......)

type
man waitpid
in linux shell.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.