Re: How to monitor a process efficiently
Re: How to monitor a process efficiently
- Subject: Re: How to monitor a process efficiently
- From: Graff <email@hidden>
- Date: Thu, 15 Jul 2004 00:12:44 -0400
I believe this will do it for you. Save this script as a stay-open
application and then run it. You will need to fill in the name of the
application you wish to monitor:
----
property longTimeToWait : 5 * minutes
property shortTimeToWait : 10
property appName : "OmniWeb"
global returnTime
global strikes
on idle
try
-- get cpu usage of program
set cpuUsage to do shell script "ps -xuww | grep -v 'awk' | awk '/"
& appName & "/ { print $3 }'"
-- if cpu usage is less than 1% then the program is proabaly idle
if ((cpuUsage as real) < 1) then
-- check 3 times each a short time apart to be sure program is
idle
set strikes to strikes + 1
if (strikes < 3) then
set returnTime to shortTimeToWait
else
-- if program is idle for 3 periods then sleep the system and
quit the applet
try
tell application "System Events"
sleep
end tell
end try
quit
--return 0
end if
else
-- program picked up cpu usage
-- reset strike count and monitoring time period
set strikes to 0
set returnTime to longTimeToWait
end if
on error
-- something went wrong with this check period
-- reset strike count and monitoring time period
set strikes to 0
set returnTime to longTimeToWait
end try
-- repeat the idle loop in a predetermined length of time
return returnTime
end idle
on run
-- set up strike counter and idle loop wait time
set strikes to 0
set returnTime to longTimeToWait
end run
----
- Ken
On Jul 14, 2004, at 9:31 PM, Whit Anderson wrote:
3D rendering take a long time, sometimes many hours. Some people set
sleep to "never" in preferences to keep their computer from going to
sleep while rendering (while they goes home and go to sleep).
Some 3D modelers would like to have the render finish, and then have
the computer go to sleep.
I've started an AppleScript that uses "do shell" to find the amount of
CPU usage by their rendering program. When the CPU usage drops to
zero, the AppleScript puts the computer to sleep.
In pseudo code, my script is basically:
set howManyMinutesToWait to 5
repeat while not (rendering program CPU usage is zero)
check rendering program CPU usage
if rendering program CPU usage is zero then
sleep
else
delay 60 * howManyMinutesToWait
end if
end repeat
The problem is that during that "delay 60 * howManyMinutesToWait", my
script is using the CPU enough to slow down the rendering. Is there a
more efficient way to approach this?
--Whit
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.