[CentOS] Re: command to ensure other command does last longer than5 seconds

Sat Apr 7 16:43:52 UTC 2007
William L. Maltby <CentOS4Bill at triad.rr.com>

On Sat, 2007-04-07 at 13:15 -0300, Rodrigo Barbosa wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Sat, Apr 07, 2007 at 12:00:14PM -0400, William L. Maltby wrote:
> > > 2) You are forgeting to take starting up time in consideration
> > > 
> > > 	Say a problem will take 2 seconds to start up, due to
> > > any reason (disk I/O, memory, swap etc). If you specify 4 seconds
> > > as the limit, the problem will actually run for only 2 seconds.
> > > 
> > > 	I have no idea how to solve this second issue.
> > > 
> > 
> > Run the pre-defined script with a nice command (maybe -20, etc.), start
> > the process in background (with a somewhat smaller nice?), capture it's
> > start time and the current time (both in seconds since epoch), take
> > difference between them and subtract that from desired run duration,
> > round to seconds/minutes, ..., use that value.
> 
> Hummm, I still don't see how that can work.
> 
> my_prio=getpriority(PRIO_PROCESS,0);
> 
> if (!(cpid=fork())) {
> 	setpriority(PRIO_PROCESS,0,-20);
> 	execvp(...);
> }
> 
> some_magic();
> setpriority(PRIO_PROCESS,cpid,my_prio);
> alarm(limit_time);
> 
> 
> So here I have the cpid, which is the PID of the process. How can I know
> when the startup is finished ? What is this some_magic() function you are
> proposing ?

No. I envision the controlling shell started at some hard-coded "nice"
value and the other process is kicked of with nice at a "lower" hard-
coded priority. Shell returns the PID of children - it is captured.

Capture the target process PID from the shell commands (no 'C'
envisioned here - otherwise I'd solve it all with sigaction calls -
"sleep" and/or "trap" in BASH) and the target process can be assumed to
start up reasonable quickly (we *do* "nice" it) or it may have desirable
attributes, like leaving a PID file in /var, ...

Also, we could do a small loop looking for CPU time used vi "ps" (if
significant enough load is imposed by the target) or such "rabbit
tracks" as PID files or whatever. If they are not available, well a SWAG
(Scientific Wild Ass Guess) may suffice (OP didn't sound like precision
was an issue at all) for OP's needs.

> 
> 
> One last quiestion: how off-topic are we ? :) ehehehe

:-) Based on past list postings for *many* other threads? Not at all!
;->

> <snip sig stuff>

--
Bill