rottmanja has asked for the wisdom of the Perl Monks concerning the following question:
package Lib::Daemon; use base qw(Exporter); our @EXPORT = qw(); use POSIX qw(setsid); use strict; sub daemonize { defined(my $pid = fork) or die "Can't fork: $!"; exit if $pid; print $pid . "PID WAS \n\n"; setsid() or die "Can't start a new session: $!"; } 1; __END__
Lib::Daemon::daemonize(); print "Starting Daemon.... \n\n"; my @thr = (); while(1){ main(); sleep(60); } sub threadMain{ print "Child Thread $_[0] \n"; print "*********************************************************** +*********************\n"; parseMain($_[0],$_[1]); return 1; } sub main{ my @instData = Lib::PLSInstance::getInstances(); for(my $i = 0; $i < @instData; $i++){ $thr[$i] = threads->new(\&threadMain, $instData[$i][2],$instDa +ta[$i][1] ) or die "Thread Died: $!"; } # start rejoining the threads for (my $i = 0; $i < @instData; $i++) { print "Joining thread $i\n"; $thr[$i]->join() or die "Thread die on join: $!"; print "\tThread $i joined back with the parent\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Threading + Daemons troubles
by zentara (Cardinal) on Aug 21, 2008 at 19:55 UTC | |
|
Re: Threading + Daemons troubles
by zentara (Cardinal) on Aug 21, 2008 at 17:10 UTC | |
|
Re: Threading + Daemons troubles
by BrowserUk (Patriarch) on Aug 21, 2008 at 17:12 UTC | |
|
Re: Threading + Daemons troubles
by BrowserUk (Patriarch) on Aug 21, 2008 at 17:27 UTC |