Reputation: 99
I have some test code:
#!/usr/bin/perl
use strict;
use warnings;
use Proc::Daemon;
my $daemon = Proc::Daemon->new;
Proc::Daemon::Init();
my $kid_pid = $daemon->Init(
{ work_dir => '/home/develop',
pid_file => 'pid.txt',
exec_command => 'perl /home/develop/test.pl ',
}
);
$| = 1;
while (1) {
my $status = $daemon->Status( [$kid_pid] );
if ( !$status ) {
my $kid_pid = $daemon->Init(
{ work_dir => '/home/develop',
pid_file => 'pid.txt',
exec_command => 'perl /home/develop/test.pl ',
}
);
}
sleep(5);
}
I need the script test.pl to know him PID. Give him a PID as an argument would be ideal, but in the arguments of Init method to give him $kid_pid ofcourse impossible. Option of reading from a file is not suitable.
And now I need to know PID of parent script. Code my $ppid = Proc::Daemon::Init();
dont work for me, because i have loop in script and he work incorrectly. $$
don't work too, because Proc::Daemon::Init()
have another PID.
Upvotes: 3
Views: 1104