Apache::ASP fork
I am trying to do a simple fork from within a Apache::ASP script. The code is as follows: <% if($pid = fork) { %> DONE... <% } elsif(defined $pid) { system("java PursuitSpider > stdout.txt"); system("gzip stdout.txt"); } %> I am forking b/c PursuitSpider takes about 2 hrs to run. The above works ok but I end up with a defunct libhttpd.ep process left around. I tried to setpgrp(0, $$) and POSIX::setsid() from within the child code but neither seem to detach correctly. Is there something else I need to do? -jason [EMAIL PROTECTED] [EMAIL PROTECTED]
Re: Apache::ASP fork
> <% > if($pid = fork) { > %> > DONE... > <% > } elsif(defined $pid) { > system("java PursuitSpider > stdout.txt"); > system("gzip stdout.txt"); > } > %> > ok but I end up with a defunct libhttpd.ep process left around. You need to exit after the second system(). However, you have a presumably huge mod_perl process only running two system() calls, so I suggest you use exec() instead of system() + exit(). One catch: you have to commands to execute and not one. exec()uting the following small sh script would do the trick: #!/bin/sh java PursuitSpider > stdout.txt gzip stdout.txt or you could call exec() as follows: exec('sh -c "java PursuitSpider > stdout.txt; gzip stdout.txt"'); Btw, I believe Java has built in support for gzip compression in the java.util.zip package which is part of the java API. ELB -- Eric L. Brine | Chicken: The egg's way of making more eggs. [EMAIL PROTECTED] | Do you always hit the nail on the thumb? ICQ# 4629314 | An optimist thinks thorn bushes have roses.
Re: Apache::ASP fork
Jason Horman wrote: > > I am forking b/c PursuitSpider takes about 2 hrs to run. The above works > ok but I end up with a defunct libhttpd.ep process left around. I tried > to setpgrp(0, $$) and POSIX::setsid() from within the child code but > neither seem to detach correctly. Is there something else I need to do? > In general, people find that forking & mod_perl are not a good mix. If you are going to get it to work, you need to set $SIG{CHLD} = 'IGNORE'; before the fork, so you don't leave your child processes zombied. Another way of doing this, should you run into other fork problems, is insert a run record into a database that gets picked up by a cron job later, and forks off a PursuitSpider when relevant. -- Joshua _ Joshua Chamas Chamas Enterprises Inc. NodeWorks >> free web link monitoring Huntington Beach, CA USA http://www.nodeworks.com1-714-625-4051