mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-12-22 20:57:53 +00:00
niceload: multiple -p
This commit is contained in:
parent
c6b955eb7d
commit
80d83aa489
36
src/niceload
36
src/niceload
|
@ -40,6 +40,7 @@ if($opt::factor and $opt::suspend) {
|
|||
help();
|
||||
exit;
|
||||
}
|
||||
|
||||
if(not (defined $opt::start_io or defined $opt::run_io
|
||||
or defined $opt::start_load or defined $opt::run_load
|
||||
or defined $opt::start_mem or defined $opt::run_mem
|
||||
|
@ -63,8 +64,9 @@ if(defined $opt::load) { multiply_binary_prefix($opt::load); }
|
|||
|
||||
my $limit = Limit->new();
|
||||
my $process = Process->new($opt::nice,@ARGV);
|
||||
if($opt::pid) {
|
||||
$process->set_pid($opt::pid);
|
||||
$::exitstatus = 0;
|
||||
if(@opt::pid) {
|
||||
$process->set_pid(@opt::pid);
|
||||
} elsif (@ARGV) {
|
||||
# Wait until limit is below start_limit and run_limit
|
||||
while($limit->over_start_limit()
|
||||
|
@ -91,6 +93,11 @@ while($process->is_alive()) {
|
|||
|
||||
exit($::exitstatus);
|
||||
|
||||
sub uniq {
|
||||
# Remove duplicates and return unique values
|
||||
return keys %{{ map { $_ => 1 } @_ }};
|
||||
}
|
||||
|
||||
sub multiply_binary_prefix {
|
||||
# Evalualte numbers with binary prefix
|
||||
# k=10^3, m=10^6, g=10^9, t=10^12, p=10^15, e=10^18, z=10^21, y=10^24
|
||||
|
@ -291,10 +298,22 @@ sub new {
|
|||
}, ref($class) || $class;
|
||||
}
|
||||
|
||||
sub pgrp {
|
||||
my $self = shift;
|
||||
my @pgrp;
|
||||
if(not $self->{'pgrp'}) {
|
||||
for(@{$self->{'pids'}}) {
|
||||
push @pgrp,-getpgrp($_);
|
||||
}
|
||||
@pgrp = uniq(@pgrp);
|
||||
@{$self->{'pgrp'}} = @pgrp;
|
||||
}
|
||||
return @{$self->{'pgrp'}};
|
||||
}
|
||||
|
||||
sub set_pid {
|
||||
my $self = shift;
|
||||
$self->{'pid'} = shift;
|
||||
push(@{$self->{'pids'}},$self->{'pid'});
|
||||
push(@{$self->{'pids'}},@_);
|
||||
$self->{'running'} = 1;
|
||||
$::exitstatus = 0;
|
||||
}
|
||||
|
@ -313,7 +332,6 @@ sub start {
|
|||
$SIG{TSTP}=\&kill_child_TSTP;
|
||||
$SIG{CONT}=\&kill_child_CONT;
|
||||
sleep 1; # Give child time to setpgrp(0,0);
|
||||
$self->{'pgrp'} = getpgrp $self->{'pid'};
|
||||
} else {
|
||||
setpgrp(0,0);
|
||||
::debug("Child pid: $$, pgrp: ",getpgrp $$,"\n");
|
||||
|
@ -345,15 +363,15 @@ sub REAPER {
|
|||
|
||||
sub kill_child_CONT {
|
||||
my $self = $Global::process;
|
||||
::debug("SIGCONT received. Killing $self->{'pid'}\n");
|
||||
kill CONT => -getpgrp($self->{'pid'});
|
||||
::debug("SIGCONT received. Killing @{$self->{'pgrp'}}\n");
|
||||
kill CONT => $self->pgrp();
|
||||
}
|
||||
|
||||
|
||||
sub kill_child_TSTP {
|
||||
my $self = $Global::process;
|
||||
::debug("SIGTSTP received. Killing $self->{'pid'} and self ($$)\n");
|
||||
kill TSTP => -getpgrp($self->{'pid'});
|
||||
kill TSTP => $self->pgrp();
|
||||
kill STOP => -$$;
|
||||
kill STOP => $$;
|
||||
}
|
||||
|
@ -362,7 +380,7 @@ sub kill_child_TSTP {
|
|||
sub kill_child_INT {
|
||||
my $self = $Global::process;
|
||||
::debug("SIGINT received. Killing $self->{'pid'} Exit\n");
|
||||
kill INT => -getpgrp($self->{'pid'});
|
||||
kill INT => $self->pgrp();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
|
|
@ -1965,6 +1965,10 @@ can be written like this:
|
|||
|
||||
@strong{cat list | parallel do_something | process_output}
|
||||
|
||||
For example: Find which host name in a list has IP address 1.2.3 4:
|
||||
|
||||
@strong{cat hosts.txt | parallel -P 100 host | grep 1.2.3.4}
|
||||
|
||||
If the processing requires more steps the for-loop like this:
|
||||
|
||||
@verbatim
|
||||
|
@ -2194,14 +2198,6 @@ GNU @strong{parallel} can often speed this up.
|
|||
|
||||
This will run 1.5 job per core, and give 1000 arguments to @strong{grep}.
|
||||
|
||||
To grep a big file in parallel use @strong{--pipe}:
|
||||
|
||||
@strong{cat bigfile | parallel --pipe grep foo}
|
||||
|
||||
Depending on your disks and CPUs it may be faster to read larger blocks:
|
||||
|
||||
@strong{cat bigfile | parallel --pipe --block 10M grep foo}
|
||||
|
||||
@chapter EXAMPLE: Using remote computers
|
||||
@anchor{EXAMPLE: Using remote computers}
|
||||
|
||||
|
|
|
@ -7,5 +7,7 @@ cat <<'EOF' | stdout parallel -j0 -L1
|
|||
echo '### --soft -f and test if child is actually suspended and thus takes longer'
|
||||
niceload --soft -t 0.2 -f 0.5 'seq 1000000 | wc;echo This should finish last'
|
||||
(sleep 1; seq 1000000 | wc;echo This should finish first)
|
||||
echo '### niceload with no arguments should give no output'
|
||||
niceload
|
||||
EOF
|
||||
|
||||
|
|
12
testsuite/tests-to-run/niceload04.sh
Executable file
12
testsuite/tests-to-run/niceload04.sh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
# force load > 10
|
||||
while uptime | grep -v age:.[1-9][0-9].[0-9][0-9] >/dev/null ; do (timeout 5 nice burnP6 2>/dev/null &) done
|
||||
|
||||
sleep 1 &
|
||||
PID1=$!
|
||||
sleep 1 &
|
||||
PID2=$!
|
||||
sleep 1 &
|
||||
PID3=$!
|
||||
stdout /usr/bin/time -f %e niceload -l 8 -H -p $PID1 -p $PID2 -p $PID3 | perl -ne '$_ >= 5 and print "OK\n"'
|
|
@ -1,4 +1,5 @@
|
|||
### --soft -f and test if child is actually suspended and thus takes longer
|
||||
### niceload with no arguments should give no output
|
||||
1000000 1000000 6888896
|
||||
This should finish first
|
||||
1000000 1000000 6888896
|
||||
|
|
1
testsuite/wanted-results/niceload04
Normal file
1
testsuite/wanted-results/niceload04
Normal file
|
@ -0,0 +1 @@
|
|||
OK
|
Loading…
Reference in a new issue