Sponsored Content
Top Forums Programming Periodic thread with clock_nanosleep Post 302741381 by Don Cragun on Saturday 8th of December 2012 10:49:39 AM
Old 12-08-2012
In addition to what jlliagre said, NTP will occasionally cause the real_time clock to shift forwards or backwards to align with the external time source. If your system supports the monotonic clock option, you could try using CLOCK_MONOTONIC instead of CLOCK_REALTIME.

You haven't said anything about the return value you observed from clock_nanosleep(). If it returned 0, it should not have awakened early according to the clock you specified in your call. If it returned early due to a signal, it was a relative sleep, and the last argument to clock_nanosleep() wasn't a null pointer then clock_nanosleep() would have stored the amount of time remaining on the requested timeout in the timespec structure pointed to by that last argument.
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

create a periodic execution of a script?

Hello every body goal: create a script that control periodicly ( every 30 min ) if a process is already actif. How can I do that? thanks (3 Replies)
Discussion started by: hoang
3 Replies

2. Shell Programming and Scripting

Tcsh periodic requires carriage return

Hello All, My first post on this forum. I am using cygwin to help me with some routine jobs on my laptop, with tcsh as my shell. I need to copy a set of files from one directory to a network drive every minute. So I have set tperiod = 1 alias periodic 'cp *.txt /cygdrive/z/Data' ... (0 Replies)
Discussion started by: OmniVision
0 Replies

3. Cybersecurity

Periodic check of user password strength

I need to periodically run a check on the passwords of the users (Redhat 5.0) to verify that all passwords meet minimal standards. I remember seeing a script years ago that grabbed the encrypted passwords from the file and checked if they matched any of the encrypted strings in another file, plus... (1 Reply)
Discussion started by: tlynnch
1 Replies

4. UNIX for Dummies Questions & Answers

Remove 1st character in periodic lines

Hi, I have a file that looks like this, the unity of information is composed of four lines, and these extends for millions. My objective is to remove the highligthed "T". How to attack this? This character is always constant in type "T" and position "1st" but the rest of the line is... (7 Replies)
Discussion started by: sargotrons
7 Replies

5. Ubuntu

Wireless periodic drops - Ubuntu 12.10

Ubuntu wireless has been fine until fresh installation of 12.10. Now, I have periodic drops of the wireless. I can manually disconnect and then reconnect to get the service back. Sometimes, I am unable to disconnect. When this happens, I have to log off and then on again. (0 Replies)
Discussion started by: jamarsh
0 Replies

6. Shell Programming and Scripting

awk Script: removing periodic boundaries

SOLVED, thank you! Edit2: Good news everyone, I managed to get it down to a "simple" problem, but I still have some syntax issues. Here is the code which troubles me: awk 'BEGIN{x2=0;x1=0;crit=0;} $1 < 1000000 {x2=$4; diffx=x2-x1; x1=x2; diffx > 3.6 ? {crit=1} : {crit=0};... (2 Replies)
Discussion started by: Consti
2 Replies

7. What is on Your Mind?

Vuejs Periodic Table by Kadin Zhang

Was working on Vue.js and stumbled upon this beautiful Vue project by Kadin Zhang Periodicity is a dynamic periodic table built with Vue.js that animates and graphs data to aid the visualization of chemical concepts. The code is available on GitHub (2 Replies)
Discussion started by: Neo
2 Replies
CLOCK_NANOSLEEP(2)					     Linux Programmer's Manual						CLOCK_NANOSLEEP(2)

NAME
clock_nanosleep - high-resolution sleep with specifiable clock SYNOPSIS
#include <time.h> int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *request, struct timespec *remain); Link with -lrt. Feature Test Macro Requirements for glibc (see feature_test_macros(7)): clock_nanosleep(): _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L DESCRIPTION
Like nanosleep(2), clock_nanosleep() allows the caller to sleep for an interval specified with nanosecond precision. It differs in allow- ing the caller to select the clock against which the sleep interval is to be measured, and in allowing the sleep interval to be specified as either an absolute or a relative value. The time values passed to and returned by this call are specified using timespec structures, defined as follows: struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds [0 .. 999999999] */ }; The clock_id argument specifies the clock against which the sleep interval is to be measured. This argument can have one of the following values: CLOCK_REALTIME A settable system-wide real-time clock. CLOCK_MONOTONIC A nonsettable, monotonically increasing clock that measures time since some unspecified point in the past that does not change after system startup. CLOCK_PROCESS_CPUTIME_ID A settable per-process clock that measures CPU time consumed by all threads in the process. See clock_getres(2) for further details on these clocks. If flags is 0, then the value specified in request is interpreted as an interval relative to the current value of the clock specified by clock_id. If flags is TIMER_ABSTIME, then request is interpreted as an absolute time as measured by the clock, clock_id. If request is less than or equal to the current value of the clock, then clock_nanosleep() returns immediately without suspending the calling thread. clock_nanosleep() suspends the execution of the calling thread until either at least the time specified by request has elapsed, or a signal is delivered that causes a signal handler to be called or that terminates the process. If the call is interrupted by a signal handler, clock_nanosleep() fails with the error EINTR. In addition, if remain is not NULL, and flags was not TIMER_ABSTIME, it returns the remaining unslept time in remain. This value can then be used to call clock_nanosleep() again and complete a (relative) sleep. RETURN VALUE
On successfully sleeping for the requested interval, clock_nanosleep() returns 0. If the call is interrupted by a signal handler or encounters an error, then it returns one of the positive error number listed in ERRORS. ERRORS
EFAULT request or remain specified an invalid address. EINTR The sleep was interrupted by a signal handler. EINVAL The value in the tv_nsec field was not in the range 0 to 999999999 or tv_sec was negative. EINVAL clock_id was invalid. (CLOCK_THREAD_CPUTIME_ID is not a permitted value for clock_id.) VERSIONS
The clock_nanosleep() system call first appeared in Linux 2.6. Support is available in glibc since version 2.1. CONFORMING TO
POSIX.1-2001. NOTES
If the interval specified in request is not an exact multiple of the granularity underlying clock (see time(7)), then the interval will be rounded up to the next multiple. Furthermore, after the sleep completes, there may still be a delay before the CPU becomes free to once again execute the calling thread. Using an absolute timer is useful for preventing timer drift problems of the type described in nanosleep(2). (Such problems are exacer- bated in programs that try to restart a relative sleep that is repeatedly interrupted by signals.) To perform a relative sleep that avoids these problems, call clock_gettime(2) for the desired clock, add the desired interval to the returned time value, and then call clock_nanosleep() with the TIMER_ABSTIME flag. clock_nanosleep() is never restarted after being interrupted by a signal handler, regardless of the use of the sigaction(2) SA_SIGACTION flag. The remain argument is unused, and unnecessary, when flags is TIMER_ABSTIME. (An absolute sleep can be restarted using the same request argument.) POSIX.1 specifies that clock_nanosleep() has no effect on signals dispositions or the signal mask. POSIX.1 specifies that after changing the value of the CLOCK_REALTIME clock via clock_settime(2), the new clock value shall be used to determine the time at which a thread blocked on an absolute clock_nanosleep() will wake up; if the new clock value falls past the end of the sleep interval, then the clock_nanosleep() call will return immediately. POSIX.1 specifies that changing the value of the CLOCK_REALTIME clock via clock_settime(2) shall have no effect on a thread that is blocked on a relative clock_nanosleep(). SEE ALSO
nanosleep(2), timer_create(2), clock_getres(2), sleep(3), usleep(3), time(7) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2010-09-10 CLOCK_NANOSLEEP(2)
All times are GMT -4. The time now is 05:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy