X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_CF X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Andrew Schulman Subject: nosleep command Date: Mon, 12 Sep 2011 13:40:07 -0400 Lines: 36 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive: encrypt X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com I'd like to provide a 'nosleep' command for Cygwin, that will prevent the host from sleeping or hibernating while a command executes. I haven't seen anything in Cygwin that currently does this, but please enlighten me if I'm wrong. Looking around for how to do this, I see two basic approaches: (1) Run SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED) to try to convince the computer not to sleep or hibernate, while the desired command executes. See for example [1], which does this. I haven't tested it yet. Looking at the documentation of SetThreadExecutionState() [2], it seems that this approach will keep the computer from sleeping when it's idle, but not when the user closes a laptop lid or pushes the power button. (2) Use the powercfg command (or PowerDuplicateScheme(), etc.) to create a temporary power scheme with sleep and hibernation disabled, then restore the original power scheme after the command has finished. See for example [3], which does this (that particular implementation needs work - powercfg needs different options in Windows XP and earlier). Which approach do people think is better? Or is there another, better way? #2 seems more fragile, in the sense that it will fail to restore the original power scheme if the parent process is killed before it finishes executing. By contrast, #1 doesn't have any cleanup to do at the end, so there's no harm done if the parent process is killed. #2 will prevent the user from manually putting the computer to sleep or hibernating, but I'm not sure if that's an advantage. Users won't necessarily know why their computer won't go to sleep when they tell it to, or why after a while it starts to work again. Whether it's worthwhile may depend on how important it is for the requested command to finish - although that still isn't guaranteed under #2, since the user can still shut the machine down. Finally, it seems likely that #1 needs lower privileges than #2, although I'm not sure about that yet. [1] http://www.vistax64.com/general-discussion/222308-vista-goes-sleep-while-burning-dvd.html#post1022013 [2] http://msdn.microsoft.com/en-us/library/aa373208(v=vs.85).aspx [3] http://superuser.com/questions/90415/prevent-sleep-in-scripts/90432#90432 -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple