 |
 |
Running FAH only when on mains power?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Sydney, Australia
Status:
Offline
|
|
Hey all
I want to get some distributed computing stuff (probably FAH as I have SETI running on 2 computers already at home) running on my iBook but I really only want it to be running when I am on mains power as the calculations really chew through batteries. Is there a way I can get it to suspend automatically when I am on battery and resume when I plug back into mains power?
A shell script or something would be fine.
tobes
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2001
Location: California
Status:
Offline
|
|
I thought this was an interesting idea so I did a little research. Unfortunately I haven't found a command yet that could be run from the terminal that would tell you what your current power source was. Not to say it doesn't exist, just that I haven't uncovered one in my casual research.
Mac OS X does provide a way for a developer to get this information through the Power Manager API's. There is the BatteryInfo Bits constant which I think could be used to determine power source. But then you're getting out of the realm of an easy shell script.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Sydney, Australia
Status:
Offline
|
|
Hmm I guess I'll look into is it a bit closer. I'll have a look at the API's when i get a chance and might right a little program to do it.
tobes
|
|
|
| |
|
|
|
 |
|
 |
|
Administrator 
Join Date: May 2000
Location: California
Status:
Online
|
|
I'm not an Applescript expert. But if Applescript can tell when you're on battery, a script could be written and saved as an application.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2002
Location: Silly Valley, Ca
Status:
Offline
|
|
AppleScript has a system attribute command in Scripting Additions that can take a Gestalt and get the status. I don't remember the gestalt for battery power.
If you have the DevTools installed you can use ioreg.
ioreg -c AppleMacIODevice -n battery | grep Flags
Should give you the line with battery flags.
I think 7 is charging, 5 is fully charged and plugged in, and 4 is unplugged.
Though it may not be so cut and dried.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2001
Location: California
Status:
Offline
|
|
Originally posted by mikkyo:
ioreg -c AppleMacIODevice -n battery | grep Flags
Neat command! I think you could combine that with a kill -STOP and a kill -CONT and have a shell script that would work. This makes me wonder what other strange and interesting CLI commands are lurking in OS X.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Sydney, Australia
Status:
Offline
|
|
Hey guys,
I just whipped this up Im not sure its the best way of doing it but it works. Well it seems to.
Now I just need to know how to get it to run say every minute. Where are the CRON files?
#!/bin/bash
batstate=`ioreg -c AppleMacIODevice -n battery | grep Flag | grep =4`
fahpid=`ps -ax | grep -v grep | grep FahCore | awk '{print $1;}'`
conspid=`ps -ax | grep -v grep | grep Fah | awk '{print $1;}'`
if [ "$batstate" != "" ]
then
kill -STOP $fahpid
kill -STOP $conspid
else
kill -CONT $fahpid
kill -CONT $conspid
fi
tobes
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2002
Location: Santa Barbara CA
Status:
Offline
|
|
Originally posted by tobes:
Hey guys,
I just whipped this up Im not sure its the best way of doing it but it works. Well it seems to.
Now I just need to know how to get it to run say every minute. Where are the CRON files?
...
tobes
If you type:
crontab -e
then you are editing your user crontab. This thread has info on how to use cron:
http://forums.macnn.com/showthread.p...hreadid=150733
|
|
|
| |
|
|
|
 |
|
 |
|
Administrator 
Join Date: May 2000
Location: California
Status:
Online
|
|
crontabs can be edited by:
GUI: CronniX
drag and drop the file to cron into the Cronnix window.
Edit the parameters as needed.
Terminal: crontab -e
hit 'i' for insert, type stuff, then hit 'esc' to stop inserting
to delete, move cursor to first character you want to delete, hit 'x' as needed
to save finished crontab and leave editor type ':wq'
I wrote up a crontab definition post here.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2002
Location: Silly Valley, Ca
Status:
Offline
|
|
I usually just make a specific crontab file for the app, like foldingtab and keep it with the app.
Every minute might be a bit extreme and suck more CPU power than you wish.
If you make a file you can put something like
*/5 * * * * cd /Users/you; ./nameofshscript
in it (run every 5 minutes) and call it foldingtab then do
crontab foldingtab
to enter it as your crontab
crontab -l
will list your current crontab.
I run stuff at a higher nice and nohuped as root so I would enter it as roots crontab.
Oh and you only need to kill the FAH parent process, its children will die with it.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|