Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run script as daemon with proc::Daemon module

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;
like image 255
user2829377 Avatar asked Apr 19 '26 04:04

user2829377


1 Answers

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;
}
like image 194
akawhy Avatar answered Apr 20 '26 19:04

akawhy