Unix Programming - Re: measureing host loads every 10 sec until an application is

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2004 > Re: measureing host loads every 10 sec until an application is





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: measureing host loads every 10 sec until an application is
Joe Chung

2004-07-17, 7:49 am

nsf470@yahoo.com (pj) writes:

> Hi,
>
> I want to measure host loads (using system(uptime)) every 10 seconds
> while I am running an application which is written in C, and write the
> host
> load average during the application execution to a file right after
> the application terminates.
>
> i.e.,
> --- Application is started
> --- measure load average (using `uptime`) every 10 seconds
> during the execution
> --- Application is finished.
> --- calculate the load average and print it out
>
> My question is how I can run system(uptime) every 10 seconds during
> the application execution using one processor machine? I was thinking
> of having two threads, but the thread blocks the other until it is
> terminated which is not what I want. I need to run two jobs (uptime
> every 10 seconds and an application executable) simultaneously and
> measureing uptime should be finished when the application is finished.
> any suggestions? thanks for any help in advance


How about something like this.

#!/bin/sh
myprog &
childpid=$!
while [ $? -eq 0 ]; do
sleep 10
/bin/uptime
kill -0 $childpid 2>/dev/null
done

where myprog is your program.

The output of this script can be redirected to some file while
can be post-processed with awk, perl, or pick your poison.

-jc
--
(apply 'concat (reverse (list "com"
(char-to-string 46) "yahoo"
(char-to-string 64) "joechung")))
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com