niceload: --prg implemented.

This commit is contained in:
Ole Tange 2012-12-10 23:16:25 +01:00
parent 80d83aa489
commit fd6044b0dc
5 changed files with 53 additions and 19 deletions

View file

@ -65,7 +65,11 @@ if(defined $opt::load) { multiply_binary_prefix($opt::load); }
my $limit = Limit->new();
my $process = Process->new($opt::nice,@ARGV);
$::exitstatus = 0;
if(@opt::pid) {
if(@opt::prg) {
# Find all pids of prg
my $out = `pidof -x @opt::prg`;
$process->set_pid(split /\s+/,$out);
} elsif(@opt::pid) {
$process->set_pid(@opt::pid);
} elsif (@ARGV) {
# Wait until limit is below start_limit and run_limit
@ -168,6 +172,7 @@ sub get_options_from_array {
"noswap|N" => \$opt::noswap,
"nice|n=i" => \$opt::nice,
"program|prg=s" => \@opt::prg,
"process|pid|p=s" => \@opt::pid,
"suspend|s=s" => \$opt::suspend,
"recheck|t=s" => \$opt::recheck,

View file

@ -7,7 +7,7 @@ niceload - slow down a program when the load average is above a certain limit
=head1 SYNOPSIS
B<niceload> [-v] [-h] [-n nice] [-I io] [-L load] [-M mem] [-N]
[--sensor program] [-t time] [-s time|-f factor] ( command | -p PID )
[--sensor program] [-t time] [-s time|-f factor] ( command | -p PID [-p PID ...] )
=head1 DESCRIPTION
@ -101,11 +101,20 @@ B<--noswap> will set both B<--start-noswap> and B<run-noswap>.
Sets niceness. See B<nice>(1).
=item B<-p> I<PID>
=item B<-p> I<PID> (alpha testing)
=item B<--pid> I<PID>
=item B<--pid> I<PID> (alpha testing)
Process ID of process to suspend.
Process ID of process to suspend. You can specify multiple process IDs
with multiple B<-p> I<PID>.
=item B<--prg> I<program> (alpha testing)
=item B<--program> I<program> (alpha testing)
Name of running program to suspend. You can specify multiple programs
with multiple B<--prg> I<program>.
=item B<--quote>

View file

@ -17,7 +17,7 @@ niceload - slow down a program when the load average is above a certain limit
@anchor{SYNOPSIS}
@strong{niceload} [-v] [-h] [-n nice] [-I io] [-L load] [-M mem] [-N]
[--sensor program] [-t time] [-s time|-f factor] ( command | -p PID )
[--sensor program] [-t time] [-s time|-f factor] ( command | -p PID [-p PID ...] )
@chapter DESCRIPTION
@anchor{DESCRIPTION}
@ -118,13 +118,23 @@ indication that the system is memory stressed.
Sets niceness. See @strong{nice}(1).
@item @strong{-p} @emph{PID}
@anchor{@strong{-p} @emph{PID}}
@item @strong{-p} @emph{PID} (alpha testing)
@anchor{@strong{-p} @emph{PID} (alpha testing)}
@item @strong{--pid} @emph{PID}
@anchor{@strong{--pid} @emph{PID}}
@item @strong{--pid} @emph{PID} (alpha testing)
@anchor{@strong{--pid} @emph{PID} (alpha testing)}
Process ID of process to suspend.
Process ID of process to suspend. You can specify multiple process IDs
with multiple @strong{-p} @emph{PID}.
@item @strong{--prg} @emph{program} (alpha testing)
@anchor{@strong{--prg} @emph{program} (alpha testing)}
@item @strong{--program} @emph{program} (alpha testing)
@anchor{@strong{--program} @emph{program} (alpha testing)}
Name of running program to suspend. You can specify multiple programs
with multiple @strong{--prg} @emph{program}.
@item @strong{--quote}
@anchor{@strong{--quote}}

View file

@ -3,10 +3,17 @@
# 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"'
sleep 2 &
export PID1=$!
sleep 2 &
export PID2=$!
sleep 2 &
export PID3=$!
echo '### multiple -p'
stdout /usr/bin/time -f %e niceload -l 9 -H -p $PID1 -p $PID2 -p $PID3 | perl -ne '$_ => 5 and print "Multiple -p OK\n"'
sleep 2 &
sleep 2 &
sleep 2 &
echo '### --prg'
stdout /usr/bin/time -f %e niceload -l 7 -H --prg sleep | perl -ne '$_ => 5 and print "--prg OK\n"'

View file

@ -1 +1,4 @@
OK
### multiple -p
Multiple -p OK
### --prg
--prg OK