Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Community > Team MacNN > Running FAH only when on mains power?

Running FAH only when on mains power?
Thread Tools
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Sydney, Australia
Status: Offline
Reply With Quote
Mar 27, 2003, 07:33 PM
 
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
Reply With Quote
Mar 28, 2003, 04:58 PM
 
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.
     
tobes  (op)
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Sydney, Australia
Status: Offline
Reply With Quote
Mar 30, 2003, 04:40 AM
 
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
Reply With Quote
Mar 30, 2003, 12:36 PM
 
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
Reply With Quote
Mar 30, 2003, 02:54 PM
 
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
Reply With Quote
Mar 31, 2003, 01:17 AM
 
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.
     
tobes  (op)
Fresh-Faced Recruit
Join Date: Nov 2002
Location: Sydney, Australia
Status: Offline
Reply With Quote
Mar 31, 2003, 05:23 AM
 
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
Reply With Quote
Mar 31, 2003, 10:24 AM
 
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
Reply With Quote
Mar 31, 2003, 10:24 AM
 
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
Reply With Quote
Mar 31, 2003, 07:05 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:13 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2