diff --git a/src/niceload b/src/niceload index 6ea1b242..484fcf6a 100755 --- a/src/niceload +++ b/src/niceload @@ -61,15 +61,18 @@ if(not defined $::opt_run_noswap) { $::opt_run_noswap = $::opt_noswap; } my $limit = Limit->new(); my $process = Process->new($::opt_nice,@ARGV); -if(not $::opt_pid) { +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() or ($limit->hard() and $limit->over_run_limit())) { $limit->sleep_for_recheck(); } + $process->start(); } -$process->start(); + while($process->is_alive()) { if($limit->over_run_limit()) { $process->suspend(); @@ -272,6 +275,13 @@ sub new { }, ref($class) || $class; } +sub set_pid { + my $self = shift; + $self->{'pid'} = shift; + push(@{$self->{'pids'}},$self->{'pid'}); + $self->{'running'} = 1; + $::exitstatus = 0; +} sub start { # Start the program @@ -347,6 +357,8 @@ sub resume { if(not $self->{'running'}) { # - = PID group map { kill "CONT", -$_ } @{$self->{'pids'}}; + # If using -p it is not in a group + map { kill "CONT", $_ } @{$self->{'pids'}}; $self->{'running'} = 1; } } @@ -358,6 +370,8 @@ sub suspend { if($self->{'running'}) { # - = PID group map { kill "STOP", -$_ } @{$self->{'pids'}}; + # If using -p it is not in a group + map { kill "STOP", $_ } @{$self->{'pids'}}; $self->{'running'} = 0; } } diff --git a/testsuite/tests-to-run/niceload02.sh b/testsuite/tests-to-run/niceload02.sh index 4c785070..f333951d 100755 --- a/testsuite/tests-to-run/niceload02.sh +++ b/testsuite/tests-to-run/niceload02.sh @@ -3,3 +3,8 @@ echo '### Test niceload exit code' niceload "perl -e 'exit(3)'" ; echo $? eq 3 niceload "perl -e 'exit(0)'" ; echo $? eq 0 + +echo '### Test -p' +perl -e '$|=1;while($t++<3){sleep(1);print "."}' & +# The above should be suspended for at least 4 seconds +stdout /usr/bin/time -f %e niceload -D -l -2 -p $! | perl -ne '$_ > 6 and print "OK\n"' diff --git a/testsuite/wanted-results/niceload02 b/testsuite/wanted-results/niceload02 index d9ed926c..9df911e4 100644 --- a/testsuite/wanted-results/niceload02 +++ b/testsuite/wanted-results/niceload02 @@ -1,3 +1,5 @@ ### Test niceload exit code 3 eq 3 0 eq 0 +### Test -p +...OK