Re: Creation of simultaneous system commands
by Abigail-II (Bishop) on Feb 26, 2004 at 17:03 UTC
|
Traditionally, one uses fork, or threads.
Abigail | [reply] |
|
|
foreach ( @your_jobs ) {
if ( $pid ) { # parent
; # do nothing
}
elsif ( defined $pid ) { # child
# do something with $_ here, and then exit:
exit;
}
else {
die "fork failure $!";
}
}
I've just started learning about forking, but this seems to be the general way to do it.
update: oop, that should've been foreach instead of while | [reply] [d/l] |
|
|
And if your jobs are external programs to be run:
fork // die || exec $_ for @jobs;
If they are subs to be called:
fork // die || exit &$_ for @jobs;
Abigail | [reply] [d/l] [select] |
Re: Creation of simultaneous system commands
by Fletch (Bishop) on Feb 26, 2004 at 17:09 UTC
|
| [reply] |
|
|
And yes, I think multiple "logins" is the only way -- forking or threading them. They more more like queries than logins but whatever...
| [reply] |
Re: Creation of simultaneous system commands
by NetWallah (Canon) on Feb 26, 2004 at 18:40 UTC
|
You could use "non-blocking" calls to Net::SNMP :
Non-blocking Objects
When a Net::SNMP object is created having non-blocking behavior, the invocation of a method associated with the object returns immediately, allowing the flow of the code to continue. When a method is invoked that would initiate a SNMP protocol exchange requiring a response, either a true value (i.e. 0x1) is returned immediately or the undefined value is returned if there was a failure. The error() method can be used to determine the cause of the failure.
The contents of the VarBindList contained in the SNMP response message can be retrieved by calling the var_bind_list() method using the object reference passed as the first argument to the callback. The value returned by the var_bind_list() method is a hash reference created using the ObjectName and the ObjectSyntax pairs in the VarBindList. The keys of the hash consist of the OBJECT IDENTIFIERs in dotted notation corresponding to each ObjectName in the VarBindList. The value of each hash entry is set equal to the value of the corresponding ObjectSyntax. The undefined value is returned if there has been a failure and the error() method may be used to determine the reason.
"Experience is a wonderful thing. It enables you to recognize a mistake when you make it again."
| [reply] |
Re: Creation of simultaneous system commands
by flyingmoose (Priest) on Feb 26, 2004 at 18:00 UTC
|
Meesa likes Proc::Background. Very simple and easy to use, and much more transparent than using fork outright. Works on both Windows and real Operating Systems. It also allows for checking on certain processes to see if they are still running, arbitrarily waiting on a process, etc.
| [reply] |
Re: Creation of simultaneous system commands
by BrowserUk (Patriarch) on Feb 26, 2004 at 22:32 UTC
|
use threads;
my @threads;
push @threads, async{
print `perl -e "
sleep 2 * 10 - $_;
print qq[job $_ completes]; " `
} for 1 .. 10;
$_->join for @threads;
__END__
job 10 completes
job 9 completes
job 8 completes
job 7 completes
job 6 completes
job 5 completes
job 4 completes
job 3 completes
job 2 completes
job 1 completes
| [reply] [d/l] |
Re: Creation of simultaneous system commands
by revdiablo (Prior) on Feb 26, 2004 at 19:31 UTC
|
Some more fuel for the fire. Check out Parallel::ForkManager. It handles the forking for you, and exports a very simple interface. I think it was designed to do pretty much exactly what you want. If you want output from the child processes, you still have to do your own IPC, but there's a whole perldoc about that: perldoc perlipc.
| [reply] |
|
|
| [reply] |