From owner-freebsd-questions Thu Jun 13 15:46:24 2002 Delivered-To: freebsd-questions@freebsd.org Received: from c015.snv.cp.net (h000.c015.snv.cp.net [209.228.35.115]) by hub.freebsd.org (Postfix) with SMTP id 54F2337B427 for ; Thu, 13 Jun 2002 15:46:01 -0700 (PDT) Received: (cpmta 26788 invoked from network); 13 Jun 2002 15:19:20 -0700 Date: 13 Jun 2002 15:19:20 -0700 Message-ID: <20020613221920.26784.cpmta@c015.snv.cp.net> X-Sent: 13 Jun 2002 22:19:20 GMT Received: from [65.16.158.66] by mail.compgeek.com with HTTP; 13 Jun 2002 15:19:20 PDT Content-Type: text/plain Content-Disposition: inline Mime-Version: 1.0 To: freebsd-questions@freebsd.org From: Jon Noack X-Mailer: Web Mail 3.9.3.11 X-Sent-From: noackjr@compgeek.com Subject: apache and background process silent death Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I have several Java network processes I need to be able to start and stop through a web interface. I am trying to do this with FreeBSD, Apache, and Perl. I also need to keep track of the PID (to stop it) and capture STDOUT and STDERR for logging. The following Perl snippet seems to do this (modified from my actual code for conciseness): if($pid = fork) { print "starting at PID $pid\n"; open PIDFILE,">/var/run/foo.pid"; print PIDFILE $pid; close PIDFILE; } elsif(defined $pid) { #Close STDIN and redirect STDOUT and STDERR to foo.log close STDIN; exec "/usr/local/bin/sudo",@execArgs,">","/var/log/foo.log","2&>1"; } else { die "unable to fork!\n"; } This succeeds in returning output and finishing via cgi-bin and the Java process is running. NOTE: sudo is necessary because the Java processes use port 80 (on a different IP address from Apache) -- it is setup correctly (group www has sudo rights to java). The Java processes and Apache correctly bind to unique IP addresses. Everything works fine for a while, but eventually the java process dies a silent death (nothing in log file, which is capturing STDERR, by the way), as if Apache was periodically cleaning processes. If I kill Apache while the java process is still alive, it also dies silently. If I run this script from the command line, everything works perfectly -- I can log off and on at will and stop/start apache all I want. I've tried launching it from within PHP, as below, with the same results -- It displays and returns but the process silently dies in a similar manner. echo "Starting Java Server...
"; $startout = `$basepath/startServer`; echo "
$startout
"; It seems the forked process is still caught in the Apache process space. Is this correct? If so, is there a way around this? Jon Noack To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message