in reply to daemon with Perl on Linux
By the way, is there any way to assign specific PID for the process? The thing is that I need to start three processes from the same script to listen on three different ports. I need to check if these processes are running using cron.sub daemonize { # Change current working directory to root chdir("$logroot") or die "Cannot change to $logroot: $!"; # Set umask to 0 umask(0); # Detach STD file handles from the terminal open (STDIN,"/dev/null") or die "Cannot read to /dev/null: +$!"; open (STDOUT,">>$stoutp") or die "Cannot write to $stoutp: +$!"; open (STDERR,">>$sterr") or die "Cannot write to $sterr: $! +"; # PID forking defined(my $pid = fork) or die "Cannot fork: $!"; exit if $pid; setsid or die "Cannot set session ID: $!"; }
|
|---|