in reply to How to make perl script work simltaneously on multiple objects
Hi,
I would go with the fork option. You seem to have a process running which detects new server instances. This would be your main loop (pseudocode):
BE AWARE: This is perlish pseudocode and should give only hints.my %found; my %active; # sighandler for sigchild $SIG{'SIGCHLD'} = sub { my $pid = waitpid; delete $active{$pid}; }; while(running) { if(my $serverid = new_server_found()) { $found{$serverid} = { 'name' => $servername, 'otherinfo' => $otherinfo, }; my $pid = fork; if(defined $pid) { # fork ok if($pid == 0) { # this is in the child do_all_stuff_necessary_for_hardening(); exit $rc; } else { # this is parent # You have the pid and you know that this # fork was concerning a server you found # probably you want to store this information $active{$pid} = $serverid; } else { # no fork => error handling die ("FATAL: Something went wrong"); } } sleep(1); }
McA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to make perl script work simltaneously on multiple objects
by slayedbylucifer (Scribe) on Apr 01, 2013 at 04:10 UTC | |
by McA (Priest) on Apr 01, 2013 at 06:43 UTC | |
by slayedbylucifer (Scribe) on Apr 05, 2013 at 06:11 UTC |