Reputation: 47
I've got a perl script I'm writing for a school assignment that needs to be run as a daemon and do certain actions when it recives signals. I read this thread How can I run a Perl script as a system daemon in linux? and tried doing what the top reply suggested but if I run my program I don't see a PID for it.
Here's the basics of my current code.
#!/usr/bin/perl
use strict;
use warnings;
use Proc::Daemon;
Proc::Daemon::Init;
my $fname = "/tmp/filename.txt";
my $datafile;
my @students;
sub filefind {finds a filename }
sub readData {reads text in file }
sub createhash { makes hash out of data }
sub printa {prints sorted data }
sub alpha { sorts data }
sub revalpha { sorts data }
filefind();
readData();
$SIG{ USR1 } = \&alph;
$SIG{ USR2 } = \&revalph;
Upvotes: 3
Views: 905
Reputation: 1608
It seems like you don't have a loop for your code. Your program just exit after running filefind()
and readData()
. You can comments Proc::Daemon::Init;
to see the procedure
To solve the problem, you can add a loop at the end:
while (1) {
sleep 10;
}
Upvotes: 1