/usr/share/doc/libproc-queue-perl/examples/sample1.pl is in libproc-queue-perl 1.23-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #!/usr/local/bin/perl -w
use Proc::Queue size => 4, debug => 1, trace => 1, delay => 0.3, ':all';
foreach (1..10) {
my $f=fork;
if(defined ($f) and $f==0) {
print "-- I'm a forked process $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n";
exit(0)
}
}
1 while wait != -1;
Proc::Queue::size(10); # changing limit to 10 concurrent processes
Proc::Queue::trace(1); # trace mode on
Proc::Queue::debug(0); # debug is off
Proc::Queue::delay(0); # no delay between fork calls
package other; # just to test it works in any package
print "\n-- Going again!\n";
foreach (1..20) {
my $f=fork;
if(defined ($f) and $f==0) {
print "-- I'm a forked process $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n";
exit(0)
}
}
1 while wait != -1;
package another;
print "\n-- Another try!\n";
Proc::Queue::size(2);
Proc::Queue::debug(1);
use Proc::Queue ':all';
my $all_ok=all_exit_ok
Proc::Queue::run_back {
print "Hello, I'm running back $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n";
},
run_back {
print "Hello, I'm also running back $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n"
},
run_back {
print "Hello, I'm running back $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n";
},
run_back {
print "Hello, I'm also running back $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n"
};
print "-- all_exit_ok return $all_ok\n";
print "\n-- And the last one!\n";
my $all_ok2=all_exit_ok
run_back {
print "Hello, I'm running back $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n";
},
run_back {
print "Hello, I'm also running back $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n";
$?=1; # I'm going to fail
},
run_back {
print "Hello, I'm running back $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n";
exit(1); # I'm going to fail too
},
run_back {
print "Hello, I'm also running back $$\n";
sleep rand 5;
print "-- I'm tired, going away $$\n"
};
print "-- all_exit_ok return $all_ok2\n";
|