Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

UFGrayMatter

macrumors newbie
Original poster
Oct 25, 2012
4
0
I'm coming home or waking up to a computer that is running 99% CPU because of a hung app. The app developers know of the issue and are working on it.

Is there a way/script that searches for apps that are hung and auto quits them?

Thanks
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Try this :

Code:
-- Application VLC as example. Replace with the hung application
on idle
	tell application "System Events"
		set PID to unix id of process "VLC"
	end tell
	set cpuUsage to (do shell script "ps -c -o %cpu='' -p " & PID) as number
	if cpuUsage is greater than "52.0" then
		tell application "VLC" to quit
		tell me to quit
	end if
	-- handler will be called every 10 seconds. Adjust to your need
	return 10
end idle

Save the script as a stay-open application.
 

UFGrayMatter

macrumors newbie
Original poster
Oct 25, 2012
4
0
Try this :

Code:
-- Application VLC as example. Replace with the hung application
on idle
	tell application "System Events"
		set PID to unix id of process "VLC"
	end tell
	set cpuUsage to (do shell script "ps -c -o %cpu='' -p " & PID) as number
	if cpuUsage is greater than "52.0" then
		tell application "VLC" to quit
		tell me to quit
	end if
	-- handler will be called every 10 seconds. Adjust to your need
	return 10
end idle

Save the script as a stay-open application.

Thank you for that - I'll give it a try.

One question - the process is a Python process - and there are two of them running at the same time. One Python process is normal, the other is the one that hangs. I currently manually quit the hung process and then restart it without the other having any issue. How would this script work for two processes being named "Python?"
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
I thought it was an application. How do you manually quit the hung process? What's the name of this app? Can you give a link for some information? Lookup the PID with Activity Monitor or top is all I can suggest.
 

UFGrayMatter

macrumors newbie
Original poster
Oct 25, 2012
4
0
attached is a screenshot of of the activity monitor - the current processes are running as they should, there are none hanging.

Both Python processes are running two different python scripts - one is sickbeard and one is couchpotato.
 

Attachments

  • Screen Shot 2012-10-26 at 6.27.54 AM.png
    Screen Shot 2012-10-26 at 6.27.54 AM.png
    22.4 KB · Views: 111

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
If sickbeard is the one likely to hang you can try this :

In Terminal :

Code:
python SickBeard.py & echo $! > /tmp/SickBeard.pid

with script :

Code:
on idle
	set PID to do shell script "cat /tmp/SickBeard.pid"
	set cpuUsage to (do shell script "ps -c -o %cpu='' -p " & PID) as number
	if cpuUsage is greater than "70.0" then
		do shell script "kill -9 " & PID
		tell me to quit
	end if
	return 10
end idle

Save the script as a stay-open application.

CouchPotato is available as a native OSX application.
 

Attachments

  • Screen shot 2012-10-27 at 00.23.17.png
    Screen shot 2012-10-27 at 00.23.17.png
    16.8 KB · Views: 220
  • Screen shot 2012-10-27 at 00.27.23.png
    Screen shot 2012-10-27 at 00.27.23.png
    66.9 KB · Views: 102

UFGrayMatter

macrumors newbie
Original poster
Oct 25, 2012
4
0
kryten2,

This works great. Thanks for the heads up with CouchPotato, I have that running now too.

Right now, if the python script hangs, sickbeard.py quits, but python stays open. Ideally I'd like to have the script that checks if sickbeard is hung quit python and then restart it as well.

Do you think that is possible?

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.