From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

#!/usr/bin/env perl
use strict;
use lib 'definitions';
use Zing;
=pod explain
- zing-daemon takes an app (zing process) and backgrounds it
- i.e. runs the zing process in the background
- zing is a Watcher which loads (and forks) a kernel
- the kernel process loads the app (from its scheme)
- the kernel is also a watcher and maintains the specified number of forks
- the supervisor tree is zing -> kernel -> app
=cut
my $z = Zing->new(scheme => ['MyApp::Sleep', [], 4]);
my $d = Zing::Daemon->new(name => 'myapp-sleep', app => $z);
$d->execute;
my $pid = do './myapp-sleep.pid';
warn "killing forked process ($pid) in 5 secs";
sleep 5;
kill 'TERM', $pid;
warn "killed process ($pid)";
unlink 'myapp-sleep.pid';