- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- HPUX: Sleep & localtime query
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2009 05:23 AM
06-26-2009 05:23 AM
I work on HPUX application and i had a query regarding the sleep & localtime system call in HPUX.
Here is the code that we have :
const uint32_t WAKE_INTERVAL_SEC(30*60);
while (true) {
// Find out what time it is
time(¤tTime);
// Thread to align wakeup with clock 30 minute i.e if it is currently 9:20 wakeup after 10 minutes,
// If it is currently 9:05, wake up after 25 minutes.
// Calculate remaining number of seconds in this half hour.
sleepTime = WAKE_INTERVAL_SEC - (currentTime % WAKE_INTERVAL_SEC);
while (1) {
sleep(sleepTime);
// Do regular work
tptr = localtime(¤tTime);
if (12 == tptr->tm_hour && tptr->tm_min
// Noon work to be done
}
}
Expected Behaviour:
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.
Actual Behaviour:
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)
Question:
- Can sleep wake up before the schedule time ( other than SIGALRM) ? Are there any other conditions where sleep could wake up before scheduled time?
- Can localtime used for comparison return wrong time ?
- 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?
Any inputs in this regards are appreciated.
Thanks & Regards,
Nirav
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2009 05:57 AM
06-26-2009 05:57 AM
SolutionThe 'sleep(3C)' manpages note:
http://docs.hp.com/en/B2355-60130/sleep.3C.html
/* begin quote */
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.
/* endof quote */
I call your attention to "...premature arousal due to another caught signal". Perhaps this explains the behavior.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2009 01:17 AM
06-27-2009 01:17 AM
Re: HPUX: Sleep & localtime query
Of course if you need to be accurate during the DST start and ends, this trickiness may not be worth it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2009 02:12 AM
06-27-2009 02:12 AM
Re: HPUX: Sleep & localtime query
Did you ever look into "cron" for
scheduling for work?
Cron allows good control. You can schedule tasks to be run every 30 minutes for example or at 12 noon a different job.
You can setup jobs to only run Monday to Friday.
Check it out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2009 12:54 AM
06-29-2009 12:54 AM
Re: HPUX: Sleep & localtime query
Thanks for the replies.
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)
So i wanted to know if there could be any other cause for this issue.
Thanks & Regards,
Nirav