#!/usr/bin/perl -w
use strict;
while (1) {
print localtime() . "\n";
sleep 1;
}
####
#!/usr/bin/perl -w
use strict;
use POSIX;
use IO::File;
my $time_to_die = 0;
my $pid = fork;
exit if $pid;
die "Couldn't fork: $!" unless defined $pid;
print "daemon pid = $$\n";
POSIX::setsid() or die "Can't start a new session: $!";
for my $n (1 .. 5) {
my $pid;
my $logfile = $n . '.log';
if ($pid = fork) {
print "child pid = $pid\n";
}
else {
my $fh = IO::File->new;
$fh->open("> $logfile") or warn "Couldn't open $logfile: $!\n";
open (STDOUT, ">&" . fileno($fh)) or warn "Couldn't redirect STDOUT to $logfile: $!\n";
STDOUT->autoflush(1);
$SIG{INT} = "IGNORE";
my $command = ("/home/brasey/daemon/timer");
exec $command;
}
}
until ($time_to_die) {
$SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&sig_handler;
sleep;
}
exit 0;
sub sig_handler {
print "time to die\n";
$time_to_die = 1;
kill ('HUP', -$$);
}
####
$| = 1;
$^F = 10000;
STDOUT->autoflush(1);