[UFO Chicago] Shell scripting, timeouts

Jesse Becker jesse_becker@yahoo.com
Fri, 14 Feb 2003 00:26:51 -0800 (PST)


--0-1410791339-1045211211=:68061
Content-Type: text/plain; charset=us-ascii
Content-Id: 
Content-Disposition: inline

--- Ian Bicking <ianb@colorstudy.com> wrote:
> There's this unreliable program (wvware) that is being
> run on a server 
> I'm using.  Sometimes it goes into an infinite loop and
> takes up lots 
> of CPU while it's just sitting there.

Someone else in the thread commented on killing a process
after it uses too much CPU time (which can be different
from walltime).  Being the nut I am, here's a small program
that will return, in seconds, the user and system time used
by a given process.  I'll merge it with my other program
later--the other code is on my laptop, which is off at the
moment.  This will *ONLY* work on linux, and nothing else. 
My other program actually has a chance of being portable...

Nice'ing a program won't do anything except make it run
slower.  Changing this value merely adjusts how the process
scheduler gives it time in the run queue; it does not
affect the actions taken by the process.

Bedtime...

--Jesse

__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com
--0-1410791339-1045211211=:68061
Content-Type: application/octet-stream; name="cputime.c"
Content-Transfer-Encoding: base64
Content-Description: cputime.c
Content-Disposition: attachment; filename="cputime.c"

CiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8c3RkbGliLmg+CiNpbmNs
dWRlIDx1bmlzdGQuaD4KI2luY2x1ZGUgPHN5cy90eXBlcy5oPgojaW5jbHVk
ZSA8c3lzL3N0YXQuaD4KI2luY2x1ZGUgPGZjbnRsLmg+CiNpbmNsdWRlIDxh
c20vcGFyYW0uaD4KCiNkZWZpbmUgQlVGIDEwMjQKCi8qIHJldHVybnMgdGlt
ZSwgaW4gc2Vjb25kcywgdXNlZCBieSBwcm9jZXNzICovCnVuc2lnbmVkIGxv
bmcgbG9uZyBjcHV0aW1lKHVuc2lnbmVkIGludCBwaWQpIHsKICAgIGludCBj
b3VudCxmZDsKICAgIGNoYXIgZmlsZW5hbWVbQlVGXTsKICAgIGNoYXIgYnVm
ZmVyW0JVRl07CiAgICB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