X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 724E03847717 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1702684002; bh=Ng05cOvIEMgUFBMVkitIkJLqlJYVPBJQbKtlcc4mzGw=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Rhw2BfEoRm57shks3twWZk8afLwaaF4Ao+ZkRokYnpn7FmuLulO/93USsOjFr+TJB CEkrHXNTQGlZdQS8NYvbKHf2ArBmjKK+TbZ2vTCgVE0XocBFVKtibEXSuwivYyILV2 xJCft4zf4p6Fvd5+7xKei67vQwdBD5SH8gSOsB5E= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D43B33858C52 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D43B33858C52 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702683964; cv=none; b=mBj1OEEwcwjsMrMJILLllMNLqseNRu906l2SKPwWXKQjjKRuMzcp5qLIutovX0uSHMYVFuyASx+rRqf85Wo/FqAMS7yEDKU7mosZ5vlqU55sjUffY8OUMrKEoHbH+zxxbMHE3iDmi6gb3Xnh/23qLxA1JtcdNZHA2s3X9BF5W6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702683964; c=relaxed/simple; bh=wJK++w4MAeohbl9QtStwgbmshx5WXzrwRTCC2YuzWZA=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=FMOvh801mww32JCZKQT7xlniLizXXq4wh/6xG5EnIkXInseHjAFhlejOsuIQEjCYknWuAXZ/gVtKrOtnzCP6IGshiYJqndejnEDOW9Ai4gyMgMlCGywGf13CBuLr4dPdNSH9jwGzZky2v+NUOoA1dO/R8QKRSs4+DUM1KoZpDDY= ARC-Authentication-Results: i=1; server2.sourceware.org X-ASG-Debug-ID: 1702683961-24039d337016d120001-w5GHUG X-Barracuda-Envelope-From: moss AT cs DOT umass DOT edu X-Barracuda-RBL-Trusted-Forwarder: 128.119.240.136 Message-ID: <910db078-35f2-00f8-0654-59c3c58535e3@cs.umass.edu> X-Barracuda-RBL-Trusted-Forwarder: 172.26.65.13 Date: Fri, 15 Dec 2023 18:46:01 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: How efficient is 'sleep'? Content-Language: en-US X-ASG-Orig-Subj: Re: How efficient is 'sleep'? To: Backwoods BC , cygwin AT cygwin DOT com References: In-Reply-To: X-Barracuda-Connect: mailsrv.cs.umass.edu[128.119.240.136] X-Barracuda-Start-Time: 1702683961 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://barramail.cs.umass.edu:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at cs.umass.edu X-Barracuda-Scan-Msg-Size: 1591 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=5.7 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.118136 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 List-Id: General Cygwin discussions and problem reports List-Archive: List-Post: List-Help: List-Subscribe: , From: Eliot Moss via Cygwin Reply-To: Eliot Moss Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "Cygwin" On 12/15/2023 4:55 PM, Backwoods BC via Cygwin wrote: > I have quite a few "service-like" scripts that I put into the > background and then have them wake up on a regular basis to do > something. I use 'sleep' for the timing of the wakeup periods. > > My question is: How efficient is 'sleep'? I know of other OSes that > just set a timer flag and the process isn't allocated any CPU time > until the timer expires. > > I know that creating a service or even using Task Scheduler are more > "proper" ways of doing this, but they are also much more work and > would require a significant learning curve as my background is > embedded systems, not Windows. I know that my lazy way probably has a > penalty, but just how bad is it? > > Thanks You could strace on it to see what system calls it makes, but I am pretty sure it sets up a timer interrupt and then waits for an event. Very efficient. It does not, for example, continually read the clock until the requested amount of time has passed. The more interesting question is this. If you coded something like: while true; do x; sleep 60; done are you ok with x starting more than 60 seconds apart, because the time to execute x itself, to fork and wait for the processes, etc., gets added into each iteration? If you prefer the invocations of x start at the start of each minute, then you need to calculate, on each iteration, how long to sleep. There's loads of info on this stackoverflow page: https://stackoverflow.com/questions/645992/sleep-until-a-specific-time-date Cheers - Eliot Moss -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple