http://www.perlmonks.org?node_id=1013294


in reply to proc Daemon

Another hint:

#!/usr/bin/perl + # daemon.pl use POSIX qw(setsid); use IO::All; use strict; use warnings; daemonize(); my $date_time; while (1) { $date_time = scalar localtime; qq($date_time\n) > io('/tmp/daemon.log'); sleep 5; } sub daemonize { defined (my $child = fork) or die qq(I really can't do that...!\n); exit if ( $child ); setsid(); open( STDIN, "</dev/null" ); # open( STOUT, ">/dev/null" ); # inferior mistake! open( STDOUT, ">/dev/null" ); + open( STDIN, ">&STDOUT" ); chdir '/'; umask(0); # ENV{PATH} = qq(what/you/really/need); + } __END__

Update: Mea culpa! I talked pretty big before. Perhaps it would have been better if someone pointed me out on this awkward typo? I've seen hints on typos already at the monastery. Anyway - i'm sorry about this.

Examine the result:

tail -f /tmp/daemon.log

Get the PID:

# ps aux | grep '[/]usr/bin/perl ./daemon.pl' | perl -ane 'print $F[1] +'; # if many... ps aux | grep '[/]usr/bin/perl ./daemon.pl' | perl -ane 'print $F[1] . + qq(\n)'

Get rid of it:

Update2:

# kill -TERM $(ps aux | grep '[/]usr/bin/perl ./daemon.pl' | perl -ane + 'print $F[1]';) # if many... kill -TERM $(ps aux | grep '[/]usr/bin/perl ./daemon.pl' | perl -ane ' +print $F[1] . qq(\n)')

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»