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

Sat Apr 7 15:47:58 UTC 2007
Rodrigo Barbosa <rodrigob at darkover.org>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, Apr 07, 2007 at 10:30:10AM +0200, Jan-Frode Myklebust wrote:
> On 2007-04-07, Shawn Everett <shawn at tandac.com> wrote:
> > Just building off Micheal's idea:
> >
> > killafter.sh <command> <time>
> > #!/bin/bash
> >
> > $1 &
> > pid=$!
> > sleep $2
> > kill -TERM $pid
> 
> Just in case it might have died an recycled the pid, refer
> to the job (%1), not the pid:
> 
> killafter.sh <command> <time>
> #!bin/bash
> $1 &
> sleep $2
> kill -TERM %1
> 
> 
> Another way of doing it might be to fork a sub-shell with
> limits:
> 
> 	(ulimit -t 1 ; top)
> 
> But this is cputime, not walltime...

You guys are forgetting 2 things:

1) Maybe he doesn't want to run the process on the background.

	This is somewhat easy to solve, with a little C program.
You trap SIG_ALARM, fork, execp, and set and alarm. Another
option would be to use wait/wait3/wait4 and alarm, which might
be simpler. Or a combination of both.

	but the main issue is

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.

[]s

- -- 
Rodrigo Barbosa
"Quid quid Latine dictum sit, altum viditur"
"Be excellent to each other ..." - Bill & Ted (Wyld Stallyns)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFGF70updyWzQ5b5ckRArZ5AJ9uRMZQoivolQa3NBR06UM2NAA0HACeMPfZ
7L8hyLtkrP51bKnSm2zr0fk=
=3jHf
-----END PGP SIGNATURE-----