]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man2/timer_create.2
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man2 / timer_create.2
index ca039a974d691fbd16cb793bb0137b3a181a88ac..a07528ba6c372b179b654c14f77971e5e88aa269 100644 (file)
@@ -1,54 +1,32 @@
 .\" Copyright (c) 2009 Linux Foundation, written by Michael Kerrisk
 .\"     <mtk.manpages@gmail.com>
 .\"
-.\" %%%LICENSE_START(VERBATIM)
-.\" Permission is granted to make and distribute verbatim copies of this
-.\" manual provided the copyright notice and this permission notice are
-.\" preserved on all copies.
+.\" SPDX-License-Identifier: Linux-man-pages-copyleft
 .\"
-.\" Permission is granted to copy and distribute modified versions of this
-.\" manual under the conditions for verbatim copying, provided that the
-.\" entire resulting derived work is distributed under the terms of a
-.\" permission notice identical to this one.
-.\"
-.\" Since the Linux kernel and libraries are constantly changing, this
-.\" manual page may be incorrect or out-of-date.  The author(s) assume no
-.\" responsibility for errors or omissions, or for damages resulting from
-.\" the use of the information contained herein.  The author(s) may not
-.\" have taken the same level of care in the production of this manual,
-.\" which is licensed free of charge, as they might when working
-.\" professionally.
-.\"
-.\" Formatted or processed versions of this manual, if unaccompanied by
-.\" the source, must acknowledge the copyright and authors of this work.
-.\" %%%LICENSE_END
-.\"
-.\" FIXME: Linux 2.6.39 adds CLOCK_BOOTTIME
-.\" Does this also affect timerfd_create()?
-.\" FIXME: Linux 2.3.0 adds CLOCK_BOOTTIME_ALARM and CLOCK_REALTIME_ALARM
-.\" Does this also affect timerfd_create()?
-.\"
-.TH TIMER_CREATE 2 2014-08-19 Linux "Linux Programmer's Manual"
+.TH TIMER_CREATE 2 2021-03-22 "Linux man-pages (unreleased)"
 .SH NAME
 timer_create \- create a POSIX per-process timer
+.SH LIBRARY
+Real-time library
+.RI ( librt ", " \-lrt )
 .SH SYNOPSIS
 .nf
-.B  #include <signal.h>
+.BR "#include <signal.h>" "           /* Definition of " SIGEV_* " constants */"
 .B  #include <time.h>
-
-.BI "int timer_create(clockid_t " clockid ", struct sigevent *" sevp ,
-.BI "                 timer_t *" timerid );
+.PP
+.BI "int timer_create(clockid_t " clockid ", struct sigevent *restrict " sevp ,
+.BI "                 timer_t *restrict " timerid );
 .fi
-
-Link with \fI\-lrt\fP.
-.sp
-.in -4n
+.PP
+.RS -4
 Feature Test Macro Requirements for glibc (see
 .BR feature_test_macros (7)):
-.in
-.sp
+.RE
+.PP
 .BR timer_create ():
-_POSIX_C_SOURCE\ >=\ 199309L
+.nf
+    _POSIX_C_SOURCE >= 199309L
+.fi
 .SH DESCRIPTION
 .BR timer_create ()
 creates a new per-process interval timer.
@@ -57,7 +35,7 @@ The ID of the new timer is returned in the buffer pointed to by
 which must be a non-null pointer.
 This ID is unique within the process, until the timer is deleted.
 The new timer is initially disarmed.
-
+.PP
 The
 .I clockid
 argument specifies the clock that the new timer uses to measure time.
@@ -82,6 +60,46 @@ A clock that measures (user and system) CPU time consumed by
 the calling thread.
 .\" The CLOCK_MONOTONIC_RAW that was added in 2.6.28 can't be used
 .\" to create a timer -- mtk, Feb 2009
+.TP
+.BR CLOCK_BOOTTIME " (Since Linux 2.6.39)"
+.\" commit 70a08cca1227dc31c784ec930099a4417a06e7d0
+Like
+.BR CLOCK_MONOTONIC ,
+this is a monotonically increasing clock.
+However, whereas the
+.B CLOCK_MONOTONIC
+clock does not measure the time while a system is suspended, the
+.B CLOCK_BOOTTIME
+clock does include the time during which the system is suspended.
+This is useful for applications that need to be suspend-aware.
+.B CLOCK_REALTIME
+is not suitable for such applications, since that clock is affected
+by discontinuous changes to the system clock.
+.TP
+.BR CLOCK_REALTIME_ALARM " (since Linux 3.0)"
+.\" commit 9a7adcf5c6dea63d2e47e6f6d2f7a6c9f48b9337
+This clock is like
+.BR CLOCK_REALTIME ,
+but will wake the system if it is suspended.
+The caller must have the
+.B CAP_WAKE_ALARM
+capability in order to set a timer against this clock.
+.TP
+.BR CLOCK_BOOTTIME_ALARM " (since Linux 3.0)"
+.\" commit 9a7adcf5c6dea63d2e47e6f6d2f7a6c9f48b9337
+This clock is like
+.BR CLOCK_BOOTTIME ,
+but will wake the system if it is suspended.
+The caller must have the
+.B CAP_WAKE_ALARM
+capability in order to set a timer against this clock.
+.TP
+.BR CLOCK_TAI " (since Linux 3.10)"
+A system-wide clock derived from wall-clock time but ignoring leap seconds.
+.PP
+See
+.BR clock_getres (2)
+for some further details on the above clocks.
 .PP
 As well as the above values,
 .I clockid
@@ -91,7 +109,7 @@ returned by a call to
 .BR clock_getcpuclockid (3)
 or
 .BR pthread_getcpuclockid (3).
-
+.PP
 The
 .I sevp
 argument points to a
@@ -100,17 +118,17 @@ structure that specifies how the caller
 should be notified when the timer expires.
 For the definition and general details of this structure, see
 .BR sigevent (7).
-
+.PP
 The
 .I sevp.sigev_notify
 field can have the following values:
 .TP
-.BR SIGEV_NONE
+.B SIGEV_NONE
 Don't asynchronously notify when the timer expires.
 Progress of the timer can be monitored using
 .BR timer_gettime (2).
 .TP
-.BR SIGEV_SIGNAL
+.B SIGEV_SIGNAL
 Upon timer expiration, generate the signal
 .I sigev_signo
 for the process.
@@ -128,7 +146,7 @@ at most one signal is queued to the process for a given timer; see
 .BR timer_getoverrun (2)
 for more details.
 .TP
-.BR SIGEV_THREAD
+.B SIGEV_THREAD
 Upon timer expiration, invoke
 .I sigev_notify_function
 as if it were the start function of a new thread.
@@ -143,7 +161,7 @@ but the signal is targeted at the thread whose ID is given in
 .IR sigev_notify_thread_id ,
 which must be a thread in the same process as the caller.
 The
-.IR sigev_notify_thread_id
+.I sigev_notify_thread_id
 field specifies a kernel thread ID, that is, the value returned by
 .BR clone (2)
 or
@@ -182,33 +200,47 @@ Clock ID,
 .IR sigev_notify ,
 .IR sigev_signo ,
 or
-.IR sigev_notify_thread_id
+.I sigev_notify_thread_id
 is invalid.
 .TP
 .B ENOMEM
 .\" glibc layer: malloc()
 Could not allocate memory.
+.TP
+.B ENOTSUP
+The kernel does not support creating a timer against this
+.IR clockid .
+.TP
+.B EPERM
+.I clockid
+was
+.B CLOCK_REALTIME_ALARM
+or
+.B CLOCK_BOOTTIME_ALARM
+but the caller did not have the
+.B CAP_WAKE_ALARM
+capability.
 .SH VERSIONS
 This system call is available since Linux 2.6.
-.SH CONFORMING TO
-POSIX.1-2001.
+.SH STANDARDS
+POSIX.1-2001, POSIX.1-2008.
 .SH NOTES
 A program may create multiple interval timers using
 .BR timer_create ().
-
+.PP
 Timers are not inherited by the child of a
 .BR fork (2),
 and are disarmed and deleted during an
 .BR execve (2).
-
+.PP
 The kernel preallocates a "queued real-time signal"
 for each timer created using
 .BR timer_create ().
 Consequently, the number of timers is limited by the
-.BR RLIMIT_SIGPENDING
+.B RLIMIT_SIGPENDING
 resource limit (see
 .BR setrlimit (2)).
-
+.PP
 The timers created by
 .BR timer_create ()
 are commonly known as "POSIX (interval) timers".
@@ -229,22 +261,47 @@ Return the overrun count for the last timer expiration.
 .IP *
 .BR timer_delete (2):
 Disarm and delete a timer.
-
+.PP
 Since Linux 3.10, the
-.IR /proc/[pid]/timers
+.IR /proc/ pid /timers
 file can be used to list the POSIX timers for the process with PID
 .IR pid .
 See
 .BR proc (5)
 for further information.
+.PP
+Since Linux 4.10,
+.\" baa73d9e478ff32d62f3f9422822b59dd9a95a21
+support for POSIX timers is a configurable option that is enabled by default.
+Kernel support can be disabled via the
+.B CONFIG_POSIX_TIMERS
+option.
 .\"
-.SS C library/kernel ABI differences
+.SS C library/kernel differences
 Part of the implementation of the POSIX timers API is provided by glibc.
+.\" See nptl/sysdeps/unix/sysv/linux/timer_create.c
 In particular:
 .IP * 3
-The functionality for
-.BR SIGEV_THREAD
+Much of the functionality for
+.B SIGEV_THREAD
 is implemented within glibc, rather than the kernel.
+(This is necessarily so,
+since the thread involved in handling the notification is one
+that must be managed by the C library POSIX threads implementation.)
+Although the notification delivered to the process is via a thread,
+internally the NPTL implementation uses a
+.I sigev_notify
+value of
+.B SIGEV_THREAD_ID
+along with a real-time signal that is reserved by the implementation (see
+.BR nptl (7)).
+.IP *
+The implementation of the default case where
+.I evp
+is NULL is handled inside glibc,
+which invokes the underlying system call with a suitably populated
+.I sigevent
+structure.
 .IP *
 The timer IDs presented at user level are maintained by glibc,
 which maps these IDs to the timer IDs employed by the kernel.
@@ -257,9 +314,11 @@ Prior to this,
 glibc provided an incomplete user-space implementation
 .RB ( CLOCK_REALTIME
 timers only) using POSIX threads,
-and current glibc falls back to this implementation on systems
+and in glibc versions before 2.17,
+.\" glibc commit 93a78ac437ba44f493333d7e2a4b0249839ce460
+the implementation falls back to this technique on systems
 running pre-2.6 Linux kernels.
-.SH EXAMPLE
+.SH EXAMPLES
 The program below takes two arguments: a sleep period in seconds,
 and a timer frequency in nanoseconds.
 The program establishes a handler for the signal it uses for the timer,
@@ -271,14 +330,14 @@ Assuming that the timer expired at least once while the program slept,
 the signal handler will be invoked,
 and the handler displays some information about the timer notification.
 The program terminates after one invocation of the signal handler.
-
+.PP
 In the following example run, the program sleeps for 1 second,
 after creating a timer that has a frequency of 100 nanoseconds.
 By the time the signal is unblocked and delivered,
 there have been around ten million overruns.
+.PP
 .in +4n
-.nf
-
+.EX
 $ \fB./a.out 1 100\fP
 Establishing handler for signal 34
 Blocking signal 34
@@ -288,21 +347,23 @@ Unblocking signal 34
 Caught signal 34
     sival_ptr = 0xbfb174f4;     *sival_ptr = 0x804c008
     overrun count = 10004886
-.fi
+.EE
 .in
 .SS Program source
 \&
-.nf
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
+.\" SRC BEGIN (timer_create.c)
+.EX
 #include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <time.h>
+#include <unistd.h>
 
 #define CLOCKID CLOCK_REALTIME
 #define SIG SIGRTMIN
 
-#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \\
+#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \e
                         } while (0)
 
 static void
@@ -314,23 +375,25 @@ print_siginfo(siginfo_t *si)
     tidp = si\->si_value.sival_ptr;
 
     printf("    sival_ptr = %p; ", si\->si_value.sival_ptr);
-    printf("    *sival_ptr = 0x%lx\\n", (long) *tidp);
+    printf("    *sival_ptr = %#jx\en", (uintmax_t) *tidp);
 
     or = timer_getoverrun(*tidp);
     if (or == \-1)
         errExit("timer_getoverrun");
     else
-        printf("    overrun count = %d\\n", or);
+        printf("    overrun count = %d\en", or);
 }
 
 static void
 handler(int sig, siginfo_t *si, void *uc)
 {
-    /* Note: calling printf() from a signal handler is not
-       strictly correct, since printf() is not async\-signal\-safe;
-       see signal(7) */
+    /* Note: calling printf() from a signal handler is not safe
+       (and should not be done in production programs), since
+       printf() is not async\-signal\-safe; see signal\-safety(7).
+       Nevertheless, we use printf() here as a simple way of
+       showing that the handler was called. */
 
-    printf("Caught signal %d\\n", sig);
+    printf("Caught signal %d\en", sig);
     print_siginfo(si);
     signal(sig, SIG_IGN);
 }
@@ -346,29 +409,29 @@ main(int argc, char *argv[])
     struct sigaction sa;
 
     if (argc != 3) {
-        fprintf(stderr, "Usage: %s <sleep\-secs> <freq\-nanosecs>\\n",
+        fprintf(stderr, "Usage: %s <sleep\-secs> <freq\-nanosecs>\en",
                 argv[0]);
         exit(EXIT_FAILURE);
     }
 
-    /* Establish handler for timer signal */
+    /* Establish handler for timer signal. */
 
-    printf("Establishing handler for signal %d\\n", SIG);
+    printf("Establishing handler for signal %d\en", SIG);
     sa.sa_flags = SA_SIGINFO;
     sa.sa_sigaction = handler;
     sigemptyset(&sa.sa_mask);
     if (sigaction(SIG, &sa, NULL) == \-1)
         errExit("sigaction");
 
-    /* Block timer signal temporarily */
+    /* Block timer signal temporarily. */
 
-    printf("Blocking signal %d\\n", SIG);
+    printf("Blocking signal %d\en", SIG);
     sigemptyset(&mask);
     sigaddset(&mask, SIG);
     if (sigprocmask(SIG_SETMASK, &mask, NULL) == \-1)
         errExit("sigprocmask");
 
-    /* Create the timer */
+    /* Create the timer. */
 
     sev.sigev_notify = SIGEV_SIGNAL;
     sev.sigev_signo = SIG;
@@ -376,9 +439,9 @@ main(int argc, char *argv[])
     if (timer_create(CLOCKID, &sev, &timerid) == \-1)
         errExit("timer_create");
 
-    printf("timer ID is 0x%lx\\n", (long) timerid);
+    printf("timer ID is %#jx\en", (uintmax_t) timerid);
 
-    /* Start the timer */
+    /* Start the timer. */
 
     freq_nanosecs = atoll(argv[2]);
     its.it_value.tv_sec = freq_nanosecs / 1000000000;
@@ -390,21 +453,22 @@ main(int argc, char *argv[])
          errExit("timer_settime");
 
     /* Sleep for a while; meanwhile, the timer may expire
-       multiple times */
+       multiple times. */
 
-    printf("Sleeping for %d seconds\\n", atoi(argv[1]));
+    printf("Sleeping for %d seconds\en", atoi(argv[1]));
     sleep(atoi(argv[1]));
 
     /* Unlock the timer signal, so that timer notification
-       can be delivered */
+       can be delivered. */
 
-    printf("Unblocking signal %d\\n", SIG);
+    printf("Unblocking signal %d\en", SIG);
     if (sigprocmask(SIG_UNBLOCK, &mask, NULL) == \-1)
         errExit("sigprocmask");
 
     exit(EXIT_SUCCESS);
 }
-.fi
+.EE
+.\" SRC END
 .SH SEE ALSO
 .ad l
 .nh