From de39f810330d9ee7dd88f97ff0c21f174074c38c Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Wed, 18 Feb 2009 05:35:09 +0100 Subject: [PATCH] Process limit detected. Passes unittest --- parallel | 40 ++++++++++++++++++++------------- parallel.1 | 2 +- unittest/actual-results/test09 | 1 + unittest/actual-results/test10 | 2 ++ unittest/tests-to-run/test09.sh | 2 +- unittest/tests-to-run/test10.sh | 6 +++++ unittest/wanted-results/test09 | 1 + unittest/wanted-results/test10 | 2 ++ 8 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 unittest/actual-results/test10 create mode 100644 unittest/tests-to-run/test10.sh create mode 100644 unittest/wanted-results/test10 diff --git a/parallel b/parallel index a171f7bc..835d01bf 100755 --- a/parallel +++ b/parallel @@ -521,6 +521,7 @@ sub min_of_args_and_processes { my $next_arg; my $max_system_proc_reached=0; my $time = time; + DoNotReap(); do { $min_of_args_and_processes++; $next_arg = get_next_arg(); @@ -528,24 +529,33 @@ sub min_of_args_and_processes { push(@args, $next_arg); } $min_of_args_and_processes % 10 or $time=time; -# if($child = fork()) { -# push (@children,$child); -# } elsif(defined $child) { -# sleep 1000000; -# } else { -# $max_system_proc_reached = 1; -# } -# debug("Time to fork ten procs ", time-$time, " process ", $min_of_args_and_processes); -# if(time-$time > 1) { -# # It took more than 1 second to fork ten processes. We should stop forking. -# # Let us give the system a little slack -# $min_of_args_and_processes = int ($min_of_args_and_processes * 0.9)+1; -# $max_system_proc_reached = 1; -# } + if($child = fork()) { + push (@children,$child); + } elsif(defined $child) { + # The child needs to take one process. + # It will be killed later + sleep 100000; + exit; + } else { + $max_system_proc_reached = 1; + } + debug("Time to fork ten procs ", time-$time, " process ", $min_of_args_and_processes); + if(time-$time > 1) { + # It took more than 1 second to fork ten processes. We should stop forking. + # Let us give the system a little slack + debug("\nLimiting processes to: $min_of_args_and_processes-10%=". + (int ($min_of_args_and_processes * 0.9)+1)."\n"); + $min_of_args_and_processes = int ($min_of_args_and_processes * 0.9)+1; + $max_system_proc_reached = 1; + } } while($min_of_args_and_processes <= $processes and defined $next_arg and not $max_system_proc_reached); -# kill 9, @children; + for $pid (@children) { + kill 15, $pid; + waitpid($pid,0); + } + wait(); unget_arg(@args); return $min_of_args_and_processes; } diff --git a/parallel.1 b/parallel.1 index 654986c3..f42d86c5 100644 --- a/parallel.1 +++ b/parallel.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "PARALLEL 1" -.TH PARALLEL 1 "2009-02-17" "perl v5.10.0" "User Contributed Perl Documentation" +.TH PARALLEL 1 "2009-02-18" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l diff --git a/unittest/actual-results/test09 b/unittest/actual-results/test09 index fddefedf..8424eda5 100644 --- a/unittest/actual-results/test09 +++ b/unittest/actual-results/test09 @@ -1,2 +1,3 @@ Force outside the file handle limit Start +end diff --git a/unittest/actual-results/test10 b/unittest/actual-results/test10 new file mode 100644 index 00000000..e624797f --- /dev/null +++ b/unittest/actual-results/test10 @@ -0,0 +1,2 @@ +33bf8b2986551515cdaff5e860618098 - +960bedf6398273937e314fb49c7b3ffa - diff --git a/unittest/tests-to-run/test09.sh b/unittest/tests-to-run/test09.sh index d588148b..e9e4224d 100644 --- a/unittest/tests-to-run/test09.sh +++ b/unittest/tests-to-run/test09.sh @@ -3,6 +3,6 @@ echo Force outside the file handle limit # 2009-02-17 Gave fork error (echo echo Start; - seq 1 100000 | perl -pe 's/^/true /'; + seq 1 20000 | perl -pe 's/^/true /'; echo echo end) | parallel -uj 0 diff --git a/unittest/tests-to-run/test10.sh b/unittest/tests-to-run/test10.sh new file mode 100644 index 00000000..4230a126 --- /dev/null +++ b/unittest/tests-to-run/test10.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# This causes problems if we kill child processes + +seq 1 40 | parallel -j 0 seq 1 10 | sort |md5sum +seq 1 40 | parallel -j 0 seq 1 10 '| parallel -j 3 echo' | sort |md5sum diff --git a/unittest/wanted-results/test09 b/unittest/wanted-results/test09 index fddefedf..8424eda5 100644 --- a/unittest/wanted-results/test09 +++ b/unittest/wanted-results/test09 @@ -1,2 +1,3 @@ Force outside the file handle limit Start +end diff --git a/unittest/wanted-results/test10 b/unittest/wanted-results/test10 new file mode 100644 index 00000000..e624797f --- /dev/null +++ b/unittest/wanted-results/test10 @@ -0,0 +1,2 @@ +33bf8b2986551515cdaff5e860618098 - +960bedf6398273937e314fb49c7b3ffa -