SPUG: Creating a NON zombie daemon

Thomas Holkenbrink Thomas_Holkenbrink at emeraldsolutions.com
Tue Apr 18 15:39:58 CDT 2000

WooHoo never mind.... POSIX gives me a returned the child PID 

>From the "POSIX - Perl interface to IEEE Std 1003.1" perldoc
$sess_id = POSIX::setsid();

$sess_id is the Child process.

I'm sending multiple arguments within the exec... so the PID changes..

use POSIX 'setsid';
chdir '/'                 or die "Can't chdir to /: $!";
open STDIN, '/dev/null'   or die "Can't read /dev/null: $!";
open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
defined(my $pid = fork)   or die "Can't fork: $!";
exit if $pid;
$sess_id = setsid() or die "Can't start a new session: $!";
open STDERR, '>&STDOUT'   or die "Can't dup stdout: $!";
$JAVA_HOME = "/usr/local/jdk117_v3";
$javaPath = "$JAVA_HOME/bin/java";
$className = "myClassName";
#$Arg 1-3 come from the program as a parameter.  @ARGV wont work in this
exec $javaPath, $className, $Arg1, $Arg2, $Arg3  or die "exec: $!";

Thanks to all for helping me out with system Vs. exec


-----Original Message-----
From: ced at carios2.ca.boeing.com [mailto:ced at carios2.ca.boeing.com]
Sent: Tuesday, April 18, 2000 12:47 PM
To: Thomas_Holkenbrink at emeraldsolutions.com; spug-list at pm.org
Subject: RE: SPUG: Creating a NON zombie daemon

> Alright .. with a little better understanding and a good read of the
> differences between the two.. System and Exec..  so the next problem is
> that the daemon is running what would be the quickest way to grep the PID
> that process... a grep through ps -ef looking for my class name??

Either that or the PID itself since the execed process
will re-use the same number.

Charles DeRykus

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
           Email to majordomo at pm.org: "action" spug-list your_address

More information about the spug-list mailing list