Re: File IO preventing sleep
Re: File IO preventing sleep
- Subject: Re: File IO preventing sleep
- From: Dean Reece <email@hidden>
- Date: Mon, 20 May 2002 09:33:41 -0700
Yes, anything that results in regular disk I/O will prevent idle sleep.
You might try stat'ing the file instead of reading it. I think a stat
will not result in disk I/O (except for the 1st time), and stat will
tell you the modification date of the file to see if it has changed
since your last stat.
Cheers,
- Dean
On Friday, May 17, 2002, at 03:18 PM, Lisa Zorn wrote:
Hello all,
I'm having a problem with sleep... Or my computer is. (= I have a
daemon application that runs all the time in the background, and my
program is preventing MacOS X's energy saver from kicking in and
putting the computer to sleep.
After running some (time-consuming, alas) tests, I think I've narrowed
down the problem to the fact that my daemon is polling a file for
changes. To be specific, there's a thread that continually uses
ifstream's getline() method to read lines; in particular, it reads to
eof, then sleeps, then tries again.
So it's (roughly):
//---------------------
while (TRUE) {
while (!mystream_->eof()) {
mystream_->getline(line, SYS_BUFFER_SIZE-1);
// do stuff with the line
}
sleep(2);
}
//---------------------
(It's polling then, but it doesn't look like it affects system
performance so I figured this is an acceptable way to do things.)
To try to figure out what's going on, I registered a callback with
IORegisterForSystemPower. When the getline() is in the loop, I do not
receive a kIOMessageCanSystemSleep. When I take getline() out (and
make sure that the inner while loop exits after a number of
iterations), I do receive it, and the system will sleep.
On a related note, running less on a file with the capital-F mode also
seems to prevent the system from sleeping, in the same way that my
program is doing.
Does anyone have any suggestions on what I should do?
Thanks for your time,
-lisa
Glucose Development Corporation -- http://www.glu.com
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.