-----Original Message-----
>From: Toddy Prawiraharjo <[EMAIL PROTECTED]>
>Sent: Aug 8, 2007 8:12 PM
>To: beginners@perl.org
>Subject: run perl as service
>
>Hi all, 
>
>I wrote a simple perl script to check some variables in SHOW STATUS in a
>mysql server. Now, how do I run it as a service/daemon?
>I want more flexibility than crontab which is based on time. Should I use
>sleep? Or is there any other alternative? Thanks in advance.
>

See:
perldoc -q 'How do I fork a daemon process?'

The basic logic is like:

sub daemon
{
    my $child = fork();
    die "can't fork\n" unless defined $child;
    exit 0 if $child;
    setsid(); #from use POSIX qw/setsid/;

    open (STDIN, "</dev/null");
    open (STDOUT, ">/dev/null");
    open (STDERR,">&STDOUT");

    chdir $rundir;
    umask(022);
    $ENV{PATH}='/bin:/usr/bin:/sbin:/usr/sbin';

    return $$;
}

--
Jeff Pang <[EMAIL PROTECTED]>
http://home.arcor.de/jeffpang/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to