I only skimmed this, but afaik the only way to get the child PID is to "fork" rather than to "exec". On Thu, May 24, 2007 10:10 am, lists@xxxxxxxxxxx wrote: > Hi, > > Summary: > > 1. I execute script1 that will run in the background (daemon) > 2. script1 needs to execute script2 and capture STDERR, STDOUT and > exitcode from script2 if script2 exits before SIGTERM is received. > 3. If I send SIGTERM to script1 it should kill script2, and write to > DB (or log file some information that it was stopped) > > Simple, isn't it? But I cannot seam to get it to work. Anyone with > some example code that does the same thing? > > > ========= > > More complex description > > I have some scripts (perl, c, php, or anything else) that simple > independent scripts that do some stuff and output STDOUT and STDERR > and exit with an exitcode. There scripts will be kept like this, and > will not change their behavior. > > Now I need to control them and also log their STDOUT, STDERR and > exitcode. Ok, that far I have come, so that I am logging the STDOUT, > STDERR and exitcode. What I am doing is that I have created an > executer that takes care of this and writing it to DB. > > Now I need to add a functionality so that when the executer receives a > SIGTERM signal it should kill the script (that was started with a > exec() call, and then log some information to the DB (that the script > was killed etc). > > I have registered the signal SIGTERM with pcntl_signal(SIGTERM, > "sig_handler"). When I am testing I just write some info to a file > when the signal is received. I created a simple testing script with a > while(true) loop and then send the signal to the script and it > successfully writes the information to the logflie. > > Ok, now I instead of a while(true) loop make an exec() call to a > script (that is running for ever) and send the signal, then it does > not write to the file as it is supposed to. I guess it is because the > script is busy running the exec command. > > I tried to then exec() it in the background. The problem there is that > it becomes a daemon and then I cannot know what that script is doing, > and it will not send any SIGCHLD to the parent, or it does, but to > init. Or actually there will be a SIGCHLD sent, as the exec() will > open its own shell, and then the shell will exit and we get the > SIGCHLD from the shell instead of the executed script. > > Is there any way to get the "child" process PID when you exec() and > send it to the background? But then, how can I capture the exitcode? > The STDERR and STDOUT is fine as I can direct it to a file and get it > from there. > > I have a really ugly workarounds: I could append an dummy variable to > the execution of the script and then do a grep of the ps -ef to get > the PID of that script. > > /Peter > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php