2008-02-12 14:32:46 +00:00
|
|
|
.\" Copyright (C) 2008 Michael Kerrisk <mtk.manpages@gmail.com>
|
|
|
|
.\"
|
|
|
|
.\" This program is free software; you can redistribute it and/or modify
|
|
|
|
.\" it under the terms of the GNU General Public License as published by
|
|
|
|
.\" the Free Software Foundation; either version 2 of the License, or
|
|
|
|
.\" (at your option) any later version.
|
|
|
|
.\"
|
|
|
|
.\" This program is distributed in the hope that it will be useful,
|
|
|
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
.\" GNU General Public License for more details.
|
|
|
|
.\"
|
|
|
|
.\" You should have received a copy of the GNU General Public License
|
|
|
|
.\" along with this program; if not, write to the Free Software
|
|
|
|
.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
.\" MA 02111-1307 USA
|
|
|
|
.\"
|
2011-09-07 17:38:41 +00:00
|
|
|
.\" FIXME: Linux 3.0: timerfd_settime() adds a TFD_TIMER_CANCEL_ON_SET flag.
|
|
|
|
.\"
|
2011-09-14 05:38:35 +00:00
|
|
|
.TH TIMERFD_CREATE 2 2011-09-14 Linux "Linux Programmer's Manual"
|
2008-02-12 14:32:46 +00:00
|
|
|
.SH NAME
|
|
|
|
timerfd_create, timerfd_settime, timerfd_gettime \-
|
|
|
|
timers that notify via file descriptors
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <sys/timerfd.h>
|
|
|
|
.sp
|
|
|
|
.BI "int timerfd_create(int " clockid ", int " flags );
|
|
|
|
.sp
|
|
|
|
.BI "int timerfd_settime(int " fd ", int " flags ,
|
|
|
|
.BI " const struct itimerspec *" new_value ,
|
2009-02-09 23:35:13 +00:00
|
|
|
.BI " struct itimerspec *" old_value );
|
2008-02-12 14:32:46 +00:00
|
|
|
.sp
|
|
|
|
.BI "int timerfd_gettime(int " fd ", struct itimerspec *" curr_value );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
These system calls create and operate on a timer
|
|
|
|
that delivers timer expiration notifications via a file descriptor.
|
|
|
|
They provide an alternative to the use of
|
|
|
|
.BR setitimer (2)
|
|
|
|
or
|
clock_nanosleep.2, execve.2, fork.2, nanosleep.2, sigaction.2, timerfd_create.2, pthread_getcpuclockid.3, ualarm.3, usleep.3, pthreads.7, time.7: Global fix: s/(3)/(2)/ in section number xrefs for timer_*() API
The POSIX timers API is implemented (mostly) within the kernel,
so thse interfaces are system calls. Although there are as yet
no man pages, when they are added they should be in Section 2,
not 3. Therefore fix those pages that currently refer to these
interfaces as being in Section 3.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2009-02-07 20:21:03 +00:00
|
|
|
.BR timer_create (2),
|
2008-02-12 14:32:46 +00:00
|
|
|
with the advantage that the file descriptor may be monitored by
|
|
|
|
.BR select (2),
|
|
|
|
.BR poll (2),
|
|
|
|
and
|
|
|
|
.BR epoll (7).
|
|
|
|
|
|
|
|
The use of these three system calls is analogous to the use of
|
clock_nanosleep.2, execve.2, fork.2, nanosleep.2, sigaction.2, timerfd_create.2, pthread_getcpuclockid.3, ualarm.3, usleep.3, pthreads.7, time.7: Global fix: s/(3)/(2)/ in section number xrefs for timer_*() API
The POSIX timers API is implemented (mostly) within the kernel,
so thse interfaces are system calls. Although there are as yet
no man pages, when they are added they should be in Section 2,
not 3. Therefore fix those pages that currently refer to these
interfaces as being in Section 3.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2009-02-07 20:21:03 +00:00
|
|
|
.BR timer_create (2),
|
|
|
|
.BR timer_settime (2),
|
2008-02-12 14:32:46 +00:00
|
|
|
and
|
clock_nanosleep.2, execve.2, fork.2, nanosleep.2, sigaction.2, timerfd_create.2, pthread_getcpuclockid.3, ualarm.3, usleep.3, pthreads.7, time.7: Global fix: s/(3)/(2)/ in section number xrefs for timer_*() API
The POSIX timers API is implemented (mostly) within the kernel,
so thse interfaces are system calls. Although there are as yet
no man pages, when they are added they should be in Section 2,
not 3. Therefore fix those pages that currently refer to these
interfaces as being in Section 3.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2009-02-07 20:21:03 +00:00
|
|
|
.BR timer_gettime (2).
|
2008-02-12 14:32:46 +00:00
|
|
|
(There is no analog of
|
clock_nanosleep.2, execve.2, fork.2, nanosleep.2, sigaction.2, timerfd_create.2, pthread_getcpuclockid.3, ualarm.3, usleep.3, pthreads.7, time.7: Global fix: s/(3)/(2)/ in section number xrefs for timer_*() API
The POSIX timers API is implemented (mostly) within the kernel,
so thse interfaces are system calls. Although there are as yet
no man pages, when they are added they should be in Section 2,
not 3. Therefore fix those pages that currently refer to these
interfaces as being in Section 3.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2009-02-07 20:21:03 +00:00
|
|
|
.BR timer_getoverrun (2),
|
2008-02-12 14:32:46 +00:00
|
|
|
since that functionality is provided by
|
|
|
|
.BR read (2),
|
|
|
|
as described below.)
|
|
|
|
.\"
|
|
|
|
.SS timerfd_create()
|
|
|
|
.BR timerfd_create ()
|
|
|
|
creates a new timer object,
|
|
|
|
and returns a file descriptor that refers to that timer.
|
|
|
|
The
|
|
|
|
.I clockid
|
|
|
|
argument specifies the clock that is used to mark the progress
|
|
|
|
of the timer, and must be either
|
|
|
|
.B CLOCK_REALTIME
|
|
|
|
or
|
|
|
|
.BR CLOCK_MONOTONIC .
|
|
|
|
.B CLOCK_REALTIME
|
|
|
|
is a settable system-wide clock.
|
|
|
|
.B CLOCK_MONOTONIC
|
accept.2, access.2, acct.2, clock_nanosleep.2, mbind.2, mincore.2, remap_file_pages.2, sched_setscheduler.2, set_mempolicy.2, splice.2, stat.2, syslog.2, timer_create.2, timerfd_create.2, truncate.2, fenv.3, ferror.3, fflush.3, fgetwc.3, fgetws.3, flockfile.3, fputwc.3, fputws.3, fread.3, getopt.3, gets.3, getwchar.3, glob.3, iconv.3, longjmp.3, pow.3, printf.3, puts.3, putwchar.3, regex.3, rpc.3, scanf.3, setjmp.3, termios.3, unlocked_stdio.3, wcswidth.3, hd.4, rtc.4, st.4, core.5, dir_colors.5, elf.5, proc.5, arp.7, ascii.7, boot.7, bootparam.7, charsets.7, futex.7, ip.7, iso_8859-11.7, man-pages.7, man.7, mdoc.samples.7, path_resolution.7, pipe.7, posixoptions.7, unicode.7, unix.7, uri.7, utf-8.7, ld.so.8: s/non-/non/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 17:20:12 +00:00
|
|
|
is a nonsettable clock that is not affected
|
2008-02-12 14:32:46 +00:00
|
|
|
by discontinuous changes in the system clock
|
|
|
|
(e.g., manual changes to system time).
|
|
|
|
The current value of each of these clocks can be retrieved using
|
clock_nanosleep.2, getrusage.2, timerfd_create.2, clock.3, clock_getcpuclockid.3, ftime.3, pthread_create.3, pthread_getcpuclockid.3, pthread_tryjoin_np.3, sem_wait.3, time.7: Global fix: Fix xrefs to clock_*.? pages to reflect move to section 2
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2009-02-07 21:10:39 +00:00
|
|
|
.BR clock_gettime (2).
|
2008-02-12 14:32:46 +00:00
|
|
|
|
2008-10-10 12:11:52 +00:00
|
|
|
Starting with Linux 2.6.27, the following values may be bitwise ORed in
|
|
|
|
.IR flags
|
|
|
|
to change the behavior of
|
|
|
|
.BR timerfd_create ():
|
|
|
|
.TP 14
|
|
|
|
.B TFD_NONBLOCK
|
|
|
|
Set the
|
|
|
|
.BR O_NONBLOCK
|
2008-10-10 14:08:53 +00:00
|
|
|
file status flag on the new open file description.
|
2008-10-10 12:11:52 +00:00
|
|
|
Using this flag saves extra calls to
|
2008-10-10 15:03:48 +00:00
|
|
|
.BR fcntl (2)
|
2008-10-10 12:11:52 +00:00
|
|
|
to achieve the same result.
|
|
|
|
.TP
|
|
|
|
.B TFD_CLOEXEC
|
|
|
|
Set the close-on-exec
|
|
|
|
.RB ( FD_CLOEXEC )
|
|
|
|
flag on the new file descriptor.
|
2008-10-29 20:43:44 +00:00
|
|
|
See the description of the
|
2008-10-10 12:11:52 +00:00
|
|
|
.B O_CLOEXEC
|
|
|
|
flag in
|
|
|
|
.BR open (2)
|
|
|
|
for reasons why this may be useful.
|
|
|
|
.PP
|
|
|
|
In Linux versions up to and including 2.6.26,
|
2008-02-12 14:32:46 +00:00
|
|
|
.I flags
|
2008-10-10 12:11:52 +00:00
|
|
|
must be specified as zero.
|
2008-02-12 14:32:46 +00:00
|
|
|
.SS timerfd_settime()
|
|
|
|
.BR timerfd_settime ()
|
|
|
|
arms (starts) or disarms (stops)
|
|
|
|
the timer referred to by the file descriptor
|
|
|
|
.IR fd .
|
|
|
|
|
|
|
|
The
|
|
|
|
.I new_value
|
|
|
|
argument specifies the initial expiration and interval for the timer.
|
|
|
|
The
|
|
|
|
.I itimer
|
|
|
|
structure used for this argument contains two fields,
|
|
|
|
each of which is in turn a structure of type
|
|
|
|
.IR timespec :
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
|
|
|
|
struct timespec {
|
|
|
|
time_t tv_sec; /* Seconds */
|
|
|
|
long tv_nsec; /* Nanoseconds */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct itimerspec {
|
|
|
|
struct timespec it_interval; /* Interval for periodic timer */
|
|
|
|
struct timespec it_value; /* Initial expiration */
|
|
|
|
};
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
.I new_value.it_value
|
|
|
|
specifies the initial expiration of the timer,
|
|
|
|
in seconds and nanoseconds.
|
|
|
|
Setting either field of
|
|
|
|
.I new_value.it_value
|
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
|
|
|
to a nonzero value arms the timer.
|
2008-02-12 14:32:46 +00:00
|
|
|
Setting both fields of
|
|
|
|
.I new_value.it_value
|
|
|
|
to zero disarms the timer.
|
|
|
|
|
|
|
|
Setting one or both fields of
|
|
|
|
.I new_value.it_interval
|
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
|
|
|
to nonzero values specifies the period, in seconds and nanoseconds,
|
2008-02-12 14:32:46 +00:00
|
|
|
for repeated timer expirations after the initial expiration.
|
|
|
|
If both fields of
|
|
|
|
.I new_value.it_interval
|
|
|
|
are zero, the timer expires just once, at the time specified by
|
|
|
|
.IR new_value.it_value .
|
|
|
|
|
|
|
|
The
|
|
|
|
.I flags
|
|
|
|
argument is either 0, to start a relative timer
|
2011-09-14 06:49:43 +00:00
|
|
|
.RI ( new_value.it_value
|
2008-02-12 14:32:46 +00:00
|
|
|
specifies a time relative to the current value of the clock specified by
|
|
|
|
.IR clockid ),
|
|
|
|
or
|
|
|
|
.BR TFD_TIMER_ABSTIME ,
|
|
|
|
to start an absolute timer
|
2008-09-23 05:07:55 +00:00
|
|
|
.RI ( new_value.it_value
|
2008-02-12 14:32:46 +00:00
|
|
|
specifies an absolute time for the clock specified by
|
|
|
|
.IR clockid ;
|
|
|
|
that is, the timer will expire when the value of that
|
|
|
|
clock reaches the value specified in
|
2008-09-23 05:17:40 +00:00
|
|
|
.IR new_value.it_value ).
|
2008-02-12 14:32:46 +00:00
|
|
|
|
2011-09-14 05:38:35 +00:00
|
|
|
If the
|
2009-02-09 23:35:13 +00:00
|
|
|
.I old_value
|
2011-09-14 05:38:35 +00:00
|
|
|
argument is not NULL, then the
|
|
|
|
.I itimerspec
|
|
|
|
structure that it points to is used to return the setting of the timer
|
|
|
|
that was current at the time of the call;
|
|
|
|
see the description of
|
2008-02-12 14:32:46 +00:00
|
|
|
.BR timerfd_gettime ()
|
|
|
|
following.
|
|
|
|
.\"
|
|
|
|
.SS timerfd_gettime()
|
|
|
|
.BR timerfd_gettime ()
|
|
|
|
returns, in
|
|
|
|
.IR curr_value ,
|
|
|
|
an
|
|
|
|
.IR itimerspec
|
2008-04-09 09:33:49 +00:00
|
|
|
structure that contains the current setting of the timer
|
2008-02-12 14:32:46 +00:00
|
|
|
referred to by the file descriptor
|
|
|
|
.IR fd .
|
|
|
|
|
|
|
|
The
|
|
|
|
.I it_value
|
|
|
|
field returns the amount of time
|
|
|
|
until the timer will next expire.
|
|
|
|
If both fields of this structure are zero,
|
|
|
|
then the timer is currently disarmed.
|
|
|
|
This field always contains a relative value, regardless of whether the
|
|
|
|
.BR TFD_TIMER_ABSTIME
|
|
|
|
flag was specified when setting the timer.
|
|
|
|
|
|
|
|
The
|
|
|
|
.I it_interval
|
|
|
|
field returns the interval of the timer.
|
|
|
|
If both fields of this structure are zero,
|
|
|
|
then the timer is set to expire just once, at the time specified by
|
|
|
|
.IR curr_value.it_value .
|
|
|
|
.SS Operating on a timer file descriptor
|
|
|
|
The file descriptor returned by
|
|
|
|
.BR timerfd_create ()
|
|
|
|
supports the following operations:
|
|
|
|
.TP
|
|
|
|
.BR read (2)
|
|
|
|
If the timer has already expired one or more times since
|
|
|
|
its settings were last modified using
|
|
|
|
.BR timerfd_settime (),
|
|
|
|
or since the last successful
|
|
|
|
.BR read (2),
|
|
|
|
then the buffer given to
|
|
|
|
.BR read (2)
|
|
|
|
returns an unsigned 8-byte integer
|
|
|
|
.RI ( uint64_t )
|
|
|
|
containing the number of expirations that have occurred.
|
|
|
|
(The returned value is in host byte order,
|
|
|
|
i.e., the native byte order for integers on the host machine.)
|
|
|
|
.IP
|
|
|
|
If no timer expirations have occurred at the time of the
|
|
|
|
.BR read (2),
|
|
|
|
then the call either blocks until the next timer expiration,
|
|
|
|
or fails with the error
|
|
|
|
.B EAGAIN
|
accept.2, connect.2, eventfd.2, flock.2, open.2, posix_fadvise.2, read.2, recv.2, sched_setscheduler.2, select_tut.2, send.2, signalfd.2, splice.2, timerfd_create.2, write.2, flockfile.3, mkfifo.3, mq_notify.3, mq_open.3, pthread_tryjoin_np.3, scanf.3, random.4, ddp.7, epoll.7, fifo.7, ip.7, pipe.7, socket.7, spufs.7: Global fix: s/non-blocking/nonblocking/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:43:10 +00:00
|
|
|
if the file descriptor has been made nonblocking
|
2008-02-12 14:32:46 +00:00
|
|
|
(via the use of the
|
|
|
|
.BR fcntl (2)
|
|
|
|
.B F_SETFL
|
|
|
|
operation to set the
|
|
|
|
.B O_NONBLOCK
|
|
|
|
flag).
|
|
|
|
.IP
|
|
|
|
A
|
|
|
|
.BR read (2)
|
|
|
|
will fail with the error
|
|
|
|
.B EINVAL
|
|
|
|
if the size of the supplied buffer is less than 8 bytes.
|
|
|
|
.TP
|
|
|
|
.BR poll "(2), " select "(2) (and similar)"
|
|
|
|
The file descriptor is readable
|
|
|
|
(the
|
|
|
|
.BR select (2)
|
|
|
|
.I readfds
|
|
|
|
argument; the
|
|
|
|
.BR poll (2)
|
|
|
|
.B POLLIN
|
|
|
|
flag)
|
|
|
|
if one or more timer expirations have occurred.
|
|
|
|
.IP
|
|
|
|
The file descriptor also supports the other file-descriptor
|
|
|
|
multiplexing APIs:
|
|
|
|
.BR pselect (2),
|
|
|
|
.BR ppoll (2),
|
|
|
|
and
|
|
|
|
.BR epoll (7).
|
|
|
|
.TP
|
|
|
|
.BR close (2)
|
|
|
|
When the file descriptor is no longer required it should be closed.
|
|
|
|
When all file descriptors associated with the same timer object
|
|
|
|
have been closed,
|
|
|
|
the timer is disarmed and its resources are freed by the kernel.
|
|
|
|
.\"
|
|
|
|
.SS fork(2) semantics
|
|
|
|
After a
|
|
|
|
.BR fork (2),
|
|
|
|
the child inherits a copy of the file descriptor created by
|
|
|
|
.BR timerfd_create ().
|
|
|
|
The file descriptor refers to the same underlying
|
|
|
|
timer object as the corresponding file descriptor in the parent,
|
|
|
|
and
|
|
|
|
.BR read (2)s
|
|
|
|
in the child will return information about
|
|
|
|
expirations of the timer.
|
|
|
|
.\"
|
|
|
|
.SS execve(2) semantics
|
|
|
|
A file descriptor created by
|
|
|
|
.BR timerfd_create ()
|
|
|
|
is preserved across
|
|
|
|
.BR execve (2),
|
|
|
|
and continues to generate timer expirations if the timer was armed.
|
|
|
|
.SH "RETURN VALUE"
|
|
|
|
On success,
|
|
|
|
.BR timerfd_create ()
|
|
|
|
returns a new file descriptor.
|
|
|
|
On error, \-1 is returned and
|
|
|
|
.I errno
|
|
|
|
is set to indicate the error.
|
|
|
|
|
|
|
|
.BR timerfd_settime ()
|
|
|
|
and
|
|
|
|
.BR timerfd_gettime ()
|
|
|
|
return 0 on success;
|
|
|
|
on error they return \-1, and set
|
|
|
|
.I errno
|
|
|
|
to indicate the error.
|
|
|
|
.SH ERRORS
|
|
|
|
.BR timerfd_create ()
|
|
|
|
can fail with the following errors:
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
The
|
|
|
|
.I clockid
|
|
|
|
argument is neither
|
|
|
|
.B CLOCK_MONOTONIC
|
|
|
|
nor
|
|
|
|
.BR CLOCK_REALTIME ;
|
2008-10-10 12:11:52 +00:00
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
.I flags
|
|
|
|
is invalid;
|
|
|
|
or, in Linux 2.6.26 or earlier,
|
2008-02-12 14:32:46 +00:00
|
|
|
.I flags
|
intro.1, time.1, adjtimex.2, capget.2, eventfd.2, fcntl.2, getrlimit.2, getsockopt.2, gettimeofday.2, intro.2, ioctl_list.2, ioperm.2, mlock.2, pivot_root.2, poll.2, prctl.2, ptrace.2, sched_setscheduler.2, select_tut.2, semget.2, sigaltstack.2, signalfd.2, sysctl.2, timer_settime.2, timerfd_create.2, wait.2, CPU_SET.3, argz_add.3, assert_perror.3, atexit.3, backtrace.3, bcmp.3, clearenv.3, ctime.3, dl_iterate_phdr.3, dlopen.3, ecvt.3, errno.3, error.3, ether_aton.3, exit.3, fenv.3, ferror.3, finite.3, flockfile.3, fnmatch.3, fpathconf.3, fpclassify.3, ftime.3, ftok.3, ftw.3, fwide.3, getaddrinfo.3, gethostbyname.3, getlogin.3, getnameinfo.3, getnetent.3, getopt.3, getprotoent.3, getrpcent.3, getservent.3, glob.3, hsearch.3, inet.3, isalpha.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, longjmp.3, lsearch.3, malloc.3, matherr.3, mblen.3, mbsinit.3, mbtowc.3, on_exit.3, printf.3, pthread_attr_init.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_equal.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedparam.3, pthread_setschedprio.3, ptsname.3, putenv.3, putgrent.3, raise.3, rcmd.3, regex.3, rexec.3, rpc.3, rpmatch.3, rtnetlink.3, scandir.3, sem_init.3, setaliasent.3, setbuf.3, setenv.3, setjmp.3, signbit.3, stdio_ext.3, strtod.3, strtol.3, strtoul.3, system.3, termios.3, timeradd.3, tzset.3, ualarm.3, wctomb.3, xdr.3, st.4, tty_ioctl.4, core.5, elf.5, proc.5, bootparam.7, capabilities.7, icmp.7, ip.7, ipv6.7, math_error.7, mdoc.samples.7, mq_overview.7, pthreads.7, raw.7, regex.7, socket.7, tcp.7, tzselect.8: Global fix: s/non-zero/nonzero/
The tendency in English, as prescribed in style guides like
Chicago MoS, is towards removing hyphens after prefixes
like "non-" etc.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-01-16 16:40:55 +00:00
|
|
|
is nonzero.
|
2008-02-12 14:32:46 +00:00
|
|
|
.TP
|
|
|
|
.B EMFILE
|
|
|
|
The per-process limit of open file descriptors has been reached.
|
|
|
|
.TP
|
|
|
|
.B ENFILE
|
|
|
|
The system-wide limit on the total number of open files has been
|
|
|
|
reached.
|
|
|
|
.TP
|
|
|
|
.B ENODEV
|
|
|
|
Could not mount (internal) anonymous inode device.
|
|
|
|
.TP
|
|
|
|
.B ENOMEM
|
|
|
|
There was insufficient kernel memory to create the timer.
|
|
|
|
.PP
|
|
|
|
.BR timerfd_settime ()
|
|
|
|
and
|
|
|
|
.BR timerfd_gettime ()
|
|
|
|
can fail with the following errors:
|
|
|
|
.TP
|
|
|
|
.B EBADF
|
|
|
|
.I fd
|
|
|
|
is not a valid file descriptor.
|
|
|
|
.TP
|
2009-02-09 23:36:28 +00:00
|
|
|
.B EFAULT
|
|
|
|
.IR new_value ,
|
|
|
|
.IR old_value ,
|
|
|
|
or
|
|
|
|
.I curr_value
|
|
|
|
is not valid a pointer.
|
|
|
|
.TP
|
2008-02-12 14:32:46 +00:00
|
|
|
.B EINVAL
|
|
|
|
.I fd
|
|
|
|
is not a valid timerfd file descriptor.
|
2009-03-10 03:31:09 +00:00
|
|
|
.PP
|
|
|
|
.BR timerfd_settime ()
|
|
|
|
can also fail with the following errors:
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
2008-02-12 14:32:46 +00:00
|
|
|
.I new_value
|
|
|
|
is not properly initialized (one of the
|
|
|
|
.I tv_nsec
|
|
|
|
falls outside the range zero to 999,999,999).
|
2009-03-10 03:35:06 +00:00
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
.\" This case only checked since 2.6.29, and 2.2.2[78].some-stable-version.
|
|
|
|
.\" In older kernel versions, no check was made for invalid flags.
|
|
|
|
.I flags
|
|
|
|
is invalid.
|
2008-02-12 14:32:46 +00:00
|
|
|
.SH VERSIONS
|
|
|
|
These system calls are available on Linux since kernel 2.6.25.
|
2009-02-09 23:36:54 +00:00
|
|
|
Library support is provided by glibc since version 2.8.
|
2008-02-12 14:32:46 +00:00
|
|
|
.SH CONFORMING TO
|
|
|
|
These system calls are Linux-specific.
|
|
|
|
.SH EXAMPLE
|
|
|
|
The following program creates a timer and then monitors its progress.
|
|
|
|
The program accepts up to three command-line arguments.
|
|
|
|
The first argument specifies the number of seconds for
|
|
|
|
the initial expiration of the timer.
|
|
|
|
The second argument specifies the interval for the timer, in seconds.
|
|
|
|
The third argument specifies the number of times the program should
|
|
|
|
allow the timer to expire before terminating.
|
|
|
|
The second and third command-line arguments are optional.
|
|
|
|
|
|
|
|
The following shell session demonstrates the use of the program:
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$" " a.out 3 1 100"
|
2008-02-12 14:32:46 +00:00
|
|
|
0.000: timer started
|
|
|
|
3.000: read: 1; total=1
|
|
|
|
4.000: read: 1; total=2
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.BR "^Z " " # type control-Z to suspend the program"
|
2008-02-12 14:32:46 +00:00
|
|
|
[1]+ Stopped ./timerfd3_demo 3 1 100
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.RB "$ " "fg" " # Resume execution after a few seconds"
|
2008-02-12 14:32:46 +00:00
|
|
|
a.out 3 1 100
|
|
|
|
9.660: read: 5; total=7
|
|
|
|
10.000: read: 1; total=8
|
|
|
|
11.000: read: 1; total=9
|
eventfd.2, execve.2, getdents.2, ioprio_set.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, malloc.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5, proc.5, cpuset.7, mq_overview.7: Global fix: Format user input in shell sessions in boldface
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:37:22 +00:00
|
|
|
.BR "^C " " # type control-C to suspend the program"
|
2008-02-12 14:32:46 +00:00
|
|
|
.fi
|
|
|
|
.in
|
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strtol.3, core.5: global fix: Add ".SS Program source" to EXAMPLE
Add ".SS Program source" to clearly distinguish shell session and
descriptive text from actual program code.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-10-28 15:51:05 +00:00
|
|
|
.SS Program source
|
eventfd.2, getdents.2, mprotect.2, signalfd.2, timerfd_create.2, wait.2, backtrace.3, clock_getcpuclockid.3, end.3, fmemopen.3, fopencookie.3, frexp.3, getaddrinfo.3, getdate.3, getgrouplist.3, getprotoent_r.3, getservent_r.3, gnu_get_libc_version.3, inet.3, inet_pton.3, makecontext.3, matherr.3, offsetof.3, pthread_attr_init.3, pthread_create.3, pthread_getattr_np.3, sem_wait.3, strftime.3, strtok.3, strtol.3, core.5: srcfix
s/\.R " "/\\\&/ as a way of getting a blank line after a .SS heading.
(Suggested by Sam Varshavchik <mrsam@courier-mta.com>)
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2008-11-05 01:42:45 +00:00
|
|
|
\&
|
2008-02-12 14:32:46 +00:00
|
|
|
.nf
|
|
|
|
.\" The commented out code here is what we currently need until
|
|
|
|
.\" the required stuff is in glibc
|
|
|
|
.\"
|
|
|
|
.\"
|
|
|
|
.\"/* Link with -lrt */
|
|
|
|
.\"#define _GNU_SOURCE
|
|
|
|
.\"#include <sys/syscall.h>
|
|
|
|
.\"#include <unistd.h>
|
|
|
|
.\"#include <time.h>
|
|
|
|
.\"#if defined(__i386__)
|
|
|
|
.\"#define __NR_timerfd_create 322
|
|
|
|
.\"#define __NR_timerfd_settime 325
|
|
|
|
.\"#define __NR_timerfd_gettime 326
|
|
|
|
.\"#endif
|
|
|
|
.\"
|
|
|
|
.\"static int
|
|
|
|
.\"timerfd_create(int clockid, int flags)
|
|
|
|
.\"{
|
|
|
|
.\" return syscall(__NR_timerfd_create, clockid, flags);
|
|
|
|
.\"}
|
|
|
|
.\"
|
|
|
|
.\"static int
|
|
|
|
.\"timerfd_settime(int fd, int flags, struct itimerspec *new_value,
|
|
|
|
.\" struct itimerspec *curr_value)
|
|
|
|
.\"{
|
|
|
|
.\" return syscall(__NR_timerfd_settime, fd, flags, new_value,
|
|
|
|
.\" curr_value);
|
|
|
|
.\"}
|
|
|
|
.\"
|
|
|
|
.\"static int
|
|
|
|
.\"timerfd_gettime(int fd, struct itimerspec *curr_value)
|
|
|
|
.\"{
|
|
|
|
.\" return syscall(__NR_timerfd_gettime, fd, curr_value);
|
|
|
|
.\"}
|
|
|
|
.\"
|
|
|
|
.\"#define TFD_TIMER_ABSTIME (1 << 0)
|
|
|
|
.\"
|
|
|
|
.\"////////////////////////////////////////////////////////////
|
|
|
|
#include <sys/timerfd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h> /* Definition of uint64_t */
|
|
|
|
|
|
|
|
#define handle_error(msg) \\
|
|
|
|
do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_elapsed_time(void)
|
|
|
|
{
|
|
|
|
static struct timespec start;
|
|
|
|
struct timespec curr;
|
|
|
|
static int first_call = 1;
|
|
|
|
int secs, nsecs;
|
|
|
|
|
|
|
|
if (first_call) {
|
|
|
|
first_call = 0;
|
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &start) == \-1)
|
|
|
|
handle_error("clock_gettime");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &curr) == \-1)
|
|
|
|
handle_error("clock_gettime");
|
|
|
|
|
|
|
|
secs = curr.tv_sec \- start.tv_sec;
|
|
|
|
nsecs = curr.tv_nsec \- start.tv_nsec;
|
|
|
|
if (nsecs < 0) {
|
|
|
|
secs\-\-;
|
|
|
|
nsecs += 1000000000;
|
|
|
|
}
|
|
|
|
printf("%d.%03d: ", secs, (nsecs + 500000) / 1000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct itimerspec new_value;
|
|
|
|
int max_exp, fd;
|
|
|
|
struct timespec now;
|
|
|
|
uint64_t exp, tot_exp;
|
|
|
|
ssize_t s;
|
|
|
|
|
|
|
|
if ((argc != 2) && (argc != 4)) {
|
|
|
|
fprintf(stderr, "%s init\-secs [interval\-secs max\-exp]\\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clock_gettime(CLOCK_REALTIME, &now) == \-1)
|
|
|
|
handle_error("clock_gettime");
|
|
|
|
|
|
|
|
/* Create a CLOCK_REALTIME absolute timer with initial
|
|
|
|
expiration and interval as specified in command line */
|
|
|
|
|
|
|
|
new_value.it_value.tv_sec = now.tv_sec + atoi(argv[1]);
|
|
|
|
new_value.it_value.tv_nsec = now.tv_nsec;
|
|
|
|
if (argc == 2) {
|
|
|
|
new_value.it_interval.tv_sec = 0;
|
|
|
|
max_exp = 1;
|
|
|
|
} else {
|
|
|
|
new_value.it_interval.tv_sec = atoi(argv[2]);
|
|
|
|
max_exp = atoi(argv[3]);
|
|
|
|
}
|
|
|
|
new_value.it_interval.tv_nsec = 0;
|
|
|
|
|
|
|
|
fd = timerfd_create(CLOCK_REALTIME, 0);
|
|
|
|
if (fd == \-1)
|
|
|
|
handle_error("timerfd_create");
|
|
|
|
|
2008-04-09 12:21:34 +00:00
|
|
|
if (timerfd_settime(fd, TFD_TIMER_ABSTIME, &new_value, NULL) == \-1)
|
2008-02-12 14:32:46 +00:00
|
|
|
handle_error("timerfd_settime");
|
|
|
|
|
|
|
|
print_elapsed_time();
|
|
|
|
printf("timer started\\n");
|
|
|
|
|
|
|
|
for (tot_exp = 0; tot_exp < max_exp;) {
|
|
|
|
s = read(fd, &exp, sizeof(uint64_t));
|
|
|
|
if (s != sizeof(uint64_t))
|
|
|
|
handle_error("read");
|
|
|
|
|
|
|
|
tot_exp += exp;
|
|
|
|
print_elapsed_time();
|
|
|
|
printf("read: %llu; total=%llu\\n",
|
|
|
|
(unsigned long long) exp,
|
|
|
|
(unsigned long long) tot_exp);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
.fi
|
2009-02-07 19:53:05 +00:00
|
|
|
.SH BUGS
|
|
|
|
Currently,
|
|
|
|
.\" 2.6.29
|
|
|
|
.BR timerfd_create ()
|
|
|
|
supports fewer types of clock IDs than
|
|
|
|
.BR timer_create (2).
|
2008-02-12 14:32:46 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR eventfd (2),
|
|
|
|
.BR poll (2),
|
|
|
|
.BR read (2),
|
|
|
|
.BR select (2),
|
|
|
|
.BR setitimer (2),
|
|
|
|
.BR signalfd (2),
|
clock_nanosleep.2, execve.2, fork.2, nanosleep.2, sigaction.2, timerfd_create.2, pthread_getcpuclockid.3, ualarm.3, usleep.3, pthreads.7, time.7: Global fix: s/(3)/(2)/ in section number xrefs for timer_*() API
The POSIX timers API is implemented (mostly) within the kernel,
so thse interfaces are system calls. Although there are as yet
no man pages, when they are added they should be in Section 2,
not 3. Therefore fix those pages that currently refer to these
interfaces as being in Section 3.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2009-02-07 20:21:03 +00:00
|
|
|
.BR timer_create (2),
|
|
|
|
.BR timer_gettime (2),
|
|
|
|
.BR timer_settime (2),
|
2008-02-12 14:32:46 +00:00
|
|
|
.BR epoll (7),
|
|
|
|
.BR time (7)
|