popen() alternative – I am using the accepted answer (pipe/fork/exec method) to solve my issue. Only difference is, instead of execl, I am using execv.
Now, my question is, does parent process have any control over child process created by execv? Lets say this whole sequence suggested in accepted answer is for tailing 1 file and I have many such files; I put this whole sequence in a function and if I call this function many times, at a point in time, is it possible to have many child tail processes around?
What I want to know is,
1) Can I have multiple child processes running at any point in time?
2) how does child processes (created by execv) terminate? after execv call does parent know when child process (created by execv) is done/terminated? – answered.
If you have a pipe from the child’s stdout, you can often avoid signal/wait aggravation by just watching for the pipe to get EOF. You still have to reap the child to avoid zombies though http://en.wikipedia.org/wiki/Zombie_process (if you don’t care about the child’s exit status, this is normally done with a double fork so you run your real subprocess as a grandchild and reap the intermediate child). The GLib code is the most complex possible example probably: http://git.gnome.org/browse/glib/tree/glib/gspawn.c#n1191