<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: HPUX: Sleep &amp;amp; localtime query in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4448000#M358342</link>
    <description>&lt;BR /&gt;Did you ever look into "cron" for&lt;BR /&gt;scheduling for work?&lt;BR /&gt;&lt;BR /&gt;Cron allows good control.  You can schedule tasks to be run every 30 minutes for example or at 12 noon a different job.&lt;BR /&gt;&lt;BR /&gt;You can setup jobs to only run Monday to Friday.  &lt;BR /&gt;&lt;BR /&gt;Check it out.&lt;BR /&gt;</description>
    <pubDate>Sat, 27 Jun 2009 09:12:37 GMT</pubDate>
    <dc:creator>Ken Martin_3</dc:creator>
    <dc:date>2009-06-27T09:12:37Z</dc:date>
    <item>
      <title>HPUX: Sleep &amp; localtime query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4447997#M358339</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;I work on HPUX application and i had a query regarding the sleep &amp;amp; localtime system call in HPUX.&lt;BR /&gt;Here is the code that we have :&lt;BR /&gt; &lt;BR /&gt;            const uint32_t  WAKE_INTERVAL_SEC(30*60); &lt;BR /&gt;            while (true) {&lt;BR /&gt; &lt;BR /&gt;            // Find out what time it is&lt;BR /&gt;            time(&amp;amp;currentTime);&lt;BR /&gt;            &lt;BR /&gt;            // Thread to align wakeup with clock 30 minute i.e if it is currently 9:20 wakeup after 10 minutes, &lt;BR /&gt;           // If it is currently 9:05, wake up after 25 minutes.&lt;BR /&gt;           // Calculate remaining number of seconds in this half hour.&lt;BR /&gt;           sleepTime = WAKE_INTERVAL_SEC - (currentTime % WAKE_INTERVAL_SEC);&lt;BR /&gt;           while (1) {&lt;BR /&gt;            &lt;BR /&gt;                 sleep(sleepTime);&lt;BR /&gt;                  &lt;BR /&gt;                   // Do regular work&lt;BR /&gt;                  tptr = localtime(&amp;amp;currentTime);&lt;BR /&gt;          &lt;BR /&gt;                 if (12 == tptr-&amp;gt;tm_hour &amp;amp;&amp;amp; tptr-&amp;gt;tm_min &lt;WAKE_INTERVAL_MIN&gt;&lt;/WAKE_INTERVAL_MIN&gt;                 {                &lt;BR /&gt;                  // Noon work to be done&lt;BR /&gt;                 }      &lt;BR /&gt;            }&lt;BR /&gt; &lt;BR /&gt;Expected Behaviour:&lt;BR /&gt;As refered in above code, we expect that every half an hour, some work to be done and if that time happens to be between 12 and 12:30am then we also do noon work.&lt;BR /&gt; &lt;BR /&gt;Actual Behaviour:&lt;BR /&gt;Most of the time it works as expected. But some times, sleep seems to exit a few seconds before 12:30 and so the logic fails and does the noon work. Ideally i would expect that noon work condition to fail, since thread has woke up at 12:30 and hence it cannot satisify noon work condition. ( Trace in syslog indicates that regular work has started at 12:30, but logging itself would have taken some time and i suspect sleep could have woken up early)&lt;BR /&gt; &lt;BR /&gt;Question:&lt;BR /&gt;- Can sleep wake up before the schedule time ( other than SIGALRM) ? Are there any other conditions where sleep could wake up before scheduled time?&lt;BR /&gt;- Can localtime used for comparison return wrong time ?&lt;BR /&gt;- Is it possible that there are some time adjustments done internally(may be for internal clock drifting etc) which results in sleep waking up a second earlier than expected or local time doing some kind of adjustment for some reason? &lt;BR /&gt; &lt;BR /&gt;Any inputs in this regards are appreciated.&lt;BR /&gt; &lt;BR /&gt;Thanks &amp;amp; Regards,&lt;BR /&gt;Nirav&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jun 2009 12:23:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4447997#M358339</guid>
      <dc:creator>Nirav Vora</dc:creator>
      <dc:date>2009-06-26T12:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: HPUX: Sleep &amp; localtime query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4447998#M358340</link>
      <description>Hi Nirav:&lt;BR /&gt;&lt;BR /&gt;The 'sleep(3C)' manpages note:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B2355-60130/sleep.3C.html" target="_blank"&gt;http://docs.hp.com/en/B2355-60130/sleep.3C.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;/* begin quote */&lt;BR /&gt;&lt;BR /&gt;Suspension time can be an arbitrary amount longer than requested due to the scheduling of other activity in the system. The value returned by sleep() is the "unslept" amount (the requested time minus the time actually slept) in case the caller had an alarm set to go off earlier than the end of the requested sleep() time, or premature arousal due to another caught signal.&lt;BR /&gt;&lt;BR /&gt;/* endof quote */&lt;BR /&gt;&lt;BR /&gt;I call your attention to "...premature arousal due to another caught signal".  Perhaps this explains the behavior.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jun 2009 12:57:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4447998#M358340</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-06-26T12:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: HPUX: Sleep &amp; localtime query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4447999#M358341</link>
      <description>If you are sleeping every 30 minutes you might not care about this but you don't want to use localtime(3) if you can help it.  Getting the local time is expensive, especially if it needs to reread TZ or tztab(4).  It might make sense to do it once, then record the offsets.&lt;BR /&gt;&lt;BR /&gt;Of course if you need to be accurate during the DST start and ends, this trickiness may not be worth it.</description>
      <pubDate>Sat, 27 Jun 2009 08:17:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4447999#M358341</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-06-27T08:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: HPUX: Sleep &amp; localtime query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4448000#M358342</link>
      <description>&lt;BR /&gt;Did you ever look into "cron" for&lt;BR /&gt;scheduling for work?&lt;BR /&gt;&lt;BR /&gt;Cron allows good control.  You can schedule tasks to be run every 30 minutes for example or at 12 noon a different job.&lt;BR /&gt;&lt;BR /&gt;You can setup jobs to only run Monday to Friday.  &lt;BR /&gt;&lt;BR /&gt;Check it out.&lt;BR /&gt;</description>
      <pubDate>Sat, 27 Jun 2009 09:12:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4448000#M358342</guid>
      <dc:creator>Ken Martin_3</dc:creator>
      <dc:date>2009-06-27T09:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: HPUX: Sleep &amp; localtime query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4448001#M358343</link>
      <description>Hello,&lt;BR /&gt;Thanks for the replies.&lt;BR /&gt;&lt;BR /&gt;In my case, sleep is getting invoked slightly before its scheduled time. We have defined  signal handlers only for SIGALRM and SIGTERM. My only suspect is SIGALRM but i dont have evidence for that .. (unless i were to add debug logs, which would be difficult in customer environment)&lt;BR /&gt;&lt;BR /&gt;So i wanted to know if there could be any other cause for this issue.&lt;BR /&gt;&lt;BR /&gt;Thanks &amp;amp; Regards,&lt;BR /&gt;Nirav</description>
      <pubDate>Mon, 29 Jun 2009 07:54:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/hpux-sleep-amp-localtime-query/m-p/4448001#M358343</guid>
      <dc:creator>Nirav Vora</dc:creator>
      <dc:date>2009-06-29T07:54:42Z</dc:date>
    </item>
  </channel>
</rss>

