| 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")))
|