Fixed bug #35469: niceload --process" doesn't work after July-2011 release.

This commit is contained in:
Ole Tange 2012-03-04 02:24:37 +01:00
parent bcebac44b1
commit 513089c881
3 changed files with 23 additions and 2 deletions

View file

@ -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();
}
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;
}
}

View file

@ -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"'

View file

@ -1,3 +1,5 @@
### Test niceload exit code
3 eq 3
0 eq 0
### Test -p
...OK