From fd6044b0dcf58bbaf46dba989cf04168fe3e191f Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Mon, 10 Dec 2012 23:16:25 +0100 Subject: [PATCH] niceload: --prg implemented. --- src/niceload | 7 ++++++- src/niceload.pod | 17 +++++++++++++---- src/niceload.texi | 22 ++++++++++++++++------ testsuite/tests-to-run/niceload04.sh | 21 ++++++++++++++------- testsuite/wanted-results/niceload04 | 5 ++++- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/niceload b/src/niceload index 54fe00d3..8b1b5c11 100755 --- a/src/niceload +++ b/src/niceload @@ -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, diff --git a/src/niceload.pod b/src/niceload.pod index b7cddc4c..eabd86dc 100644 --- a/src/niceload.pod +++ b/src/niceload.pod @@ -7,7 +7,7 @@ niceload - slow down a program when the load average is above a certain limit =head1 SYNOPSIS B [-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. Sets niceness. See B(1). -=item B<-p> I +=item B<-p> I (alpha testing) -=item B<--pid> I +=item B<--pid> I (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. + + +=item B<--prg> I (alpha testing) + +=item B<--program> I (alpha testing) + +Name of running program to suspend. You can specify multiple programs +with multiple B<--prg> I. =item B<--quote> diff --git a/src/niceload.texi b/src/niceload.texi index eaf025de..c42124b8 100644 --- a/src/niceload.texi +++ b/src/niceload.texi @@ -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}} diff --git a/testsuite/tests-to-run/niceload04.sh b/testsuite/tests-to-run/niceload04.sh index 63a2c6e0..9092125b 100755 --- a/testsuite/tests-to-run/niceload04.sh +++ b/testsuite/tests-to-run/niceload04.sh @@ -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"' diff --git a/testsuite/wanted-results/niceload04 b/testsuite/wanted-results/niceload04 index d86bac9d..1f46a994 100644 --- a/testsuite/wanted-results/niceload04 +++ b/testsuite/wanted-results/niceload04 @@ -1 +1,4 @@ -OK +### multiple -p +Multiple -p OK +### --prg +--prg OK