Continual::Process - (re)start dead process
use Continual::Process; use Continual::Process::Loop; my $loop = Continual::Process::Loop->new( instances => [ Continual::Process->new( name => 'job1', code => sub { my $pid = fork; if ($pid) { return $pid; } say "Hello world"; sleep 5; say "Bye, bye world"; exit 1; }, instances => 4, )->create_instance(), Continual::Process->new( name => 'job2', code => sub { my $pid = fork; if ($pid) { return $pid; } exec 'perl -ne "sleep 1"'; exit 1; }, )->create_instance(), ] ); $loop->run();
Continual::Process with Continual::Process::Loop is a way how to run a process forever.
Continual::Process creates Continual::Process::Instance which runs in a loop and if it dies, it starts again.
The code for starting a process is OS-agnostic. The only condition is that the code must return PID of the new process.
Continual::Process supports more loops:
name of process (only for identification)
CodeRef which start new process and returned PID of new process
PID
code-sub must return PID of the new process or die!
for example Linux and fork:
code => sub { if (my $pid = fork) { return $pid; } ... exit 1; }
or Windows and Win32::Process
code => sub { my ($instance) = @_; Win32::Process::Create( $ProcessObj, "C:\\winnt\\system32\\notepad.exe", "notepad temp.txt", 0, NORMAL_PRIORITY_CLASS, "." ) || die "Process ".$instance->name." start fail: ".$^E; return $ProcessObj->GetProcessID(); }
best way is use Continual::Process::Helper prepare_fork or prepare_run method
prepare_fork
prepare_run
count of running instances
default 1
create and return list of Continual::Process::Instance
Copyright (C) Avast Software.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Jan Seidl <seidl@avast.com>
To install Continual::Process, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Continual::Process
CPAN shell
perl -MCPAN -e shell install Continual::Process
For more information on module installation, please visit the detailed CPAN module installation guide.