parallel: Speedup finding shell of (grand)*parent pid.

This commit is contained in:
Ole Tange 2019-06-25 23:58:22 +02:00
parent f8782f43a7
commit 7aa0394278
2 changed files with 24 additions and 1 deletions

View file

@ -222,7 +222,9 @@ Quote of the month:
New in this release: New in this release:
* {= uq() =} will cause the replacement string to be unquoted. Example: parallel echo '{=uq()=}.jpg' ::: '*' * {= uq; =} will cause the replacement string to be unquoted. Example: parallel echo '{=uq;=}.jpg' ::: '*'
* Speedup of startup by 40%: Find the parent shell differerently on GNU/Linux, cache information about the CPU and which setpgrp method to make GNU Parallel start 40% faster.
https://techieroop.com/how-to-run-multiple-bash-scripts-in-parallel/ https://techieroop.com/how-to-run-multiple-bash-scripts-in-parallel/

View file

@ -5442,6 +5442,27 @@ sub which(@) {
"-zsh" => ["zsh", "sh"], "-zsh" => ["zsh", "sh"],
); );
} }
if($^O eq "linux") {
# Optimized for GNU/Linux
my $testpid = $pid;
my $shellpath;
while($testpid) {
if($shellpath = readlink "/proc/$testpid/exe") {
if($shellpath =~ m:/$shell$:o) {
::debug("init", "proc which ".$shellpath." => ");
return $shellpath;
}
}
if(open(my $fd, "<", "/proc/$testpid/stat")) {
my $line = <$fd>;
close $fd;
$testpid = (split /\s+/, $line)[3];
} else {
# Something is wrong: fall back to old method
last;
}
}
}
# if -sh or -csh try readlink /proc/$$/exe # if -sh or -csh try readlink /proc/$$/exe
my ($children_of_ref, $parent_of_ref, $name_of_ref) = pid_table(); my ($children_of_ref, $parent_of_ref, $name_of_ref) = pid_table();
my $shellpath; my $shellpath;