15507a2aeSRuslan Ermilov.\" Copyright (c) 2005 David Xu <[email protected]> 2b1e515a3SDavid Xu.\" All rights reserved. 3bb5eebe6SDavid Xu.\" 4bb5eebe6SDavid Xu.\" Redistribution and use in source and binary forms, with or without 5bb5eebe6SDavid Xu.\" modification, are permitted provided that the following conditions 6bb5eebe6SDavid Xu.\" are met: 7bb5eebe6SDavid Xu.\" 1. Redistributions of source code must retain the above copyright 8bb5eebe6SDavid Xu.\" notice(s), this list of conditions and the following disclaimer as 9bb5eebe6SDavid Xu.\" the first lines of this file unmodified other than the possible 10bb5eebe6SDavid Xu.\" addition of one or more copyright notices. 11bb5eebe6SDavid Xu.\" 2. Redistributions in binary form must reproduce the above copyright 12bb5eebe6SDavid Xu.\" notice(s), this list of conditions and the following disclaimer in 13bb5eebe6SDavid Xu.\" the documentation and/or other materials provided with the 14bb5eebe6SDavid Xu.\" distribution. 15bb5eebe6SDavid Xu.\" 16bb5eebe6SDavid Xu.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 17bb5eebe6SDavid Xu.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18bb5eebe6SDavid Xu.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19bb5eebe6SDavid Xu.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE 20bb5eebe6SDavid Xu.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21bb5eebe6SDavid Xu.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22bb5eebe6SDavid Xu.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23bb5eebe6SDavid Xu.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24bb5eebe6SDavid Xu.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25bb5eebe6SDavid Xu.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26bb5eebe6SDavid Xu.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27bb5eebe6SDavid Xu.\" 28bb5eebe6SDavid Xu.\" $FreeBSD$ 29bb5eebe6SDavid Xu.\" 305507a2aeSRuslan Ermilov.Dd September 11, 2000 31bb5eebe6SDavid Xu.Dt TIMER_SETTIME 2 32bb5eebe6SDavid Xu.Os 33bb5eebe6SDavid Xu.Sh NAME 345507a2aeSRuslan Ermilov.Nm timer_getoverrun , 355507a2aeSRuslan Ermilov.Nm timer_gettime , 36bb5eebe6SDavid Xu.Nm timer_settime 375507a2aeSRuslan Ermilov.Nd "per-process timers (REALTIME)" 38bb5eebe6SDavid Xu.Sh LIBRARY 39e9311906SDavid Xu.Lb librt 40bb5eebe6SDavid Xu.Sh SYNOPSIS 41bb5eebe6SDavid Xu.In time.h 42bb5eebe6SDavid Xu.Ft int 43bb5eebe6SDavid Xu.Fn timer_getoverrun "timer_t timerid" 44bb5eebe6SDavid Xu.Ft int 45bb5eebe6SDavid Xu.Fn timer_gettime "timer_t timerid" "struct itimerspec *value" 46bb5eebe6SDavid Xu.Ft int 475507a2aeSRuslan Ermilov.Fo timer_settime 485507a2aeSRuslan Ermilov.Fa "timer_t timerid" "int flags" "const struct itimerspec *restrict value" 495507a2aeSRuslan Ermilov.Fa "struct itimerspec *restrict ovalue" 505507a2aeSRuslan Ermilov.Fc 51bb5eebe6SDavid Xu.Sh DESCRIPTION 52bb5eebe6SDavid XuThe 53bb5eebe6SDavid Xu.Fn timer_gettime 545507a2aeSRuslan Ermilovsystem call stores the amount of time until the specified timer, 55bb5eebe6SDavid Xu.Fa timerid , 56bb5eebe6SDavid Xuexpires and the reload value of the timer into the space pointed to by the 57bb5eebe6SDavid Xu.Fa value 585507a2aeSRuslan Ermilovargument. 595507a2aeSRuslan ErmilovThe 605507a2aeSRuslan Ermilov.Va it_value 615507a2aeSRuslan Ermilovmember of this structure contains the amount of time 625507a2aeSRuslan Ermilovbefore the timer expires, or zero if the timer is disarmed. 635507a2aeSRuslan ErmilovThis value is 64bb5eebe6SDavid Xureturned as the interval until timer expiration, even if the timer was armed 655507a2aeSRuslan Ermilovwith absolute time. 665507a2aeSRuslan ErmilovThe 675507a2aeSRuslan Ermilov.Va it_interval 685507a2aeSRuslan Ermilovmember of 695507a2aeSRuslan Ermilov.Fa value 705507a2aeSRuslan Ermilovcontains the reload 71bb5eebe6SDavid Xuvalue last set by 72bb5eebe6SDavid Xu.Fn timer_settime . 73bb5eebe6SDavid Xu.Pp 74bb5eebe6SDavid XuThe 75bb5eebe6SDavid Xu.Fn timer_settime 765507a2aeSRuslan Ermilovsystem call sets the time until the next expiration of the timer specified 77bb5eebe6SDavid Xuby 78bb5eebe6SDavid Xu.Fa timerid 795507a2aeSRuslan Ermilovfrom the 805507a2aeSRuslan Ermilov.Va it_value 815507a2aeSRuslan Ermilovmember of the 825507a2aeSRuslan Ermilov.Fa value 835507a2aeSRuslan Ermilovargument and arms the timer if the 845507a2aeSRuslan Ermilov.Va it_value 855507a2aeSRuslan Ermilovmember of 865507a2aeSRuslan Ermilov.Fa value 875507a2aeSRuslan Ermilovis non-zero. 885507a2aeSRuslan ErmilovIf the specified timer was already 89bb5eebe6SDavid Xuarmed when 90bb5eebe6SDavid Xu.Fn timer_settime 91bb5eebe6SDavid Xuis called, this call resets the time until next expiration to the value 925507a2aeSRuslan Ermilovspecified. 935507a2aeSRuslan ErmilovIf the 945507a2aeSRuslan Ermilov.Va it_value 955507a2aeSRuslan Ermilovmember of 965507a2aeSRuslan Ermilov.Fa value 975507a2aeSRuslan Ermilovis zero, the timer is disarmed. 98bb5eebe6SDavid XuIf the timer is disarmed, then pending signal is removed. 99bb5eebe6SDavid Xu.Pp 1005507a2aeSRuslan ErmilovIf the flag 1015507a2aeSRuslan Ermilov.Dv TIMER_ABSTIME 1025507a2aeSRuslan Ermilovis not set in the argument 103bb5eebe6SDavid Xu.Fa flags , 104bb5eebe6SDavid Xu.Fn timer_settime 105bb5eebe6SDavid Xubehaves as if the time until next expiration is set to 1065507a2aeSRuslan Ermilovbe equal to the interval specified by the 1075507a2aeSRuslan Ermilov.Va it_value 1085507a2aeSRuslan Ermilovmember of 1095507a2aeSRuslan Ermilov.Fa value . 1105507a2aeSRuslan ErmilovThat is, 1115507a2aeSRuslan Ermilovthe timer expires in 1125507a2aeSRuslan Ermilov.Va it_value 1135507a2aeSRuslan Ermilovnanoseconds from when the call is made. 1145507a2aeSRuslan ErmilovIf the flag 1155507a2aeSRuslan Ermilov.Dv TIMER_ABSTIME 1165507a2aeSRuslan Ermilovis set in the argument 1175507a2aeSRuslan Ermilov.Fa flags , 118bb5eebe6SDavid Xu.Fn timer_settime 119bb5eebe6SDavid Xubehaves as if the time until next expiration is set to be equal to the 120bb5eebe6SDavid Xudifference between the absolute time specified by the it_value member of 121bb5eebe6SDavid Xuvalue and the current value of the clock associated with 122bb5eebe6SDavid Xu.Fa timerid . 123bb5eebe6SDavid XuThat is, the timer expires when the clock reaches the value specified by the 1245507a2aeSRuslan Ermilov.Va it_value 1255507a2aeSRuslan Ermilovmember of 1265507a2aeSRuslan Ermilov.Fa value . 1275507a2aeSRuslan ErmilovIf the specified time has already passed, the 1285507a2aeSRuslan Ermilovsystem call succeeds and the expiration notification is made. 129bb5eebe6SDavid Xu.Pp 1305507a2aeSRuslan ErmilovThe reload value of the timer is set to the value specified by the 1315507a2aeSRuslan Ermilov.Va it_interval 1325507a2aeSRuslan Ermilovmember of 1335507a2aeSRuslan Ermilov.Fa value . 1345507a2aeSRuslan ErmilovWhen a timer is armed with a non-zero 1355507a2aeSRuslan Ermilov.Va it_interval , 1365507a2aeSRuslan Ermilova periodic 137bb5eebe6SDavid Xu(or repetitive) timer is specified. 138bb5eebe6SDavid Xu.Pp 139bb5eebe6SDavid XuTime values that are between two consecutive non-negative integer multiples of 1405507a2aeSRuslan Ermilovthe resolution of the specified timer are rounded up to the larger multiple of 1415507a2aeSRuslan Ermilovthe resolution. 1425507a2aeSRuslan ErmilovQuantization error will not cause the timer to expire earlier 143bb5eebe6SDavid Xuthan the rounded time value. 144bb5eebe6SDavid Xu.Pp 1455507a2aeSRuslan ErmilovIf the argument 1465507a2aeSRuslan Ermilov.Fa ovalue 1475507a2aeSRuslan Ermilovis not 1485507a2aeSRuslan Ermilov.Dv NULL , 1495507a2aeSRuslan Ermilovthe 150bb5eebe6SDavid Xu.Fn timer_settime 1515507a2aeSRuslan Ermilovsystem call stores, in the location referenced by 1525507a2aeSRuslan Ermilov.Fa ovalue , 1535507a2aeSRuslan Ermilova value representing 154bb5eebe6SDavid Xuthe previous amount of time before the timer would have expired, or zero if the 1555507a2aeSRuslan Ermilovtimer was disarmed, together with the previous timer reload value. 1565507a2aeSRuslan ErmilovTimers do not 157bb5eebe6SDavid Xuexpire before their scheduled time. 158bb5eebe6SDavid Xu.Pp 159bb5eebe6SDavid XuOnly a single signal is queued to the process for a given timer at any point in 1605507a2aeSRuslan Ermilovtime. 1615507a2aeSRuslan ErmilovWhen a timer for which a signal is still pending expires, no signal is 1625507a2aeSRuslan Ermilovqueued, and a timer overrun will occur. 1635507a2aeSRuslan ErmilovWhen a timer expiration signal is 164bb5eebe6SDavid Xuaccepted by a process, the 165bb5eebe6SDavid Xu.Fn timer_getoverrun 1665507a2aeSRuslan Ermilovsystem call returns the timer expiration overrun count for the specified timer. 167bb5eebe6SDavid XuThe overrun count returned contains the number of extra timer expirations that 168bb5eebe6SDavid Xuoccurred between the time the signal was generated (queued) and when it was 1695507a2aeSRuslan Ermilovaccepted, up to but not including an maximum of 1705507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX . 1715507a2aeSRuslan ErmilovIf the number of 1725507a2aeSRuslan Ermilovsuch extra expirations is greater than or equal to 1735507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX , 1745507a2aeSRuslan Ermilovthen the overrun count is set to 1755507a2aeSRuslan Ermilov.Brq Dv DELAYTIMER_MAX . 1765507a2aeSRuslan ErmilovThe value returned by 177bb5eebe6SDavid Xu.Fn timer_getoverrun 1785507a2aeSRuslan Ermilovapplies to the most recent expiration signal acceptance for the timer. 1795507a2aeSRuslan ErmilovIf no 180bb5eebe6SDavid Xuexpiration signal has been delivered for the timer, the return value of 181bb5eebe6SDavid Xu.Fn timer_getoverrun 182bb5eebe6SDavid Xuis unspecified. 183bb5eebe6SDavid Xu.Sh RETURN VALUES 184bb5eebe6SDavid XuIf the 185bb5eebe6SDavid Xu.Fn timer_getoverrun 1865507a2aeSRuslan Ermilovsystem call succeeds, it returns the timer expiration overrun count as explained 187bb5eebe6SDavid Xuabove. 1885507a2aeSRuslan ErmilovOtherwise the value \-1 is returned, and the global variable 1895507a2aeSRuslan Ermilov.Va errno 1905507a2aeSRuslan Ermilovis set to indicate the error. 191bb5eebe6SDavid Xu.Pp 1925507a2aeSRuslan Ermilov.Rv -std timer_gettime timer_settime 193bb5eebe6SDavid Xu.Sh ERRORS 194bb5eebe6SDavid XuThe 195bb5eebe6SDavid Xu.Fn timer_settime 1965507a2aeSRuslan Ermilovsystem call 197bb5eebe6SDavid Xuwill fail if: 198bb5eebe6SDavid Xu.Bl -tag -width Er 199bb5eebe6SDavid Xu.It Bq Er EINVAL 2005507a2aeSRuslan ErmilovA 2015507a2aeSRuslan Ermilov.Fa value 2025507a2aeSRuslan Ermilovstructure specified a nanosecond value less than zero or greater than 2035507a2aeSRuslan Ermilovor equal to 1000 million, and the 2045507a2aeSRuslan Ermilov.Va it_value 2055507a2aeSRuslan Ermilovmember of that structure did not 206bb5eebe6SDavid Xuspecify zero seconds and nanoseconds. 207bb5eebe6SDavid Xu.El 208bb5eebe6SDavid Xu.Pp 2095507a2aeSRuslan ErmilovThese system calls may fail if: 210bb5eebe6SDavid Xu.Bl -tag -width Er 211bb5eebe6SDavid Xu.It Bq Er EINVAL 212bb5eebe6SDavid XuThe 213bb5eebe6SDavid Xu.Fa timerid 214bb5eebe6SDavid Xuargument does not correspond to an ID returned by 215bb5eebe6SDavid Xu.Fn timer_create 216bb5eebe6SDavid Xubut not yet deleted by 217bb5eebe6SDavid Xu.Fn timer_delete . 218bb5eebe6SDavid Xu.El 219bb5eebe6SDavid Xu.Pp 2205507a2aeSRuslan ErmilovThe 2215507a2aeSRuslan Ermilov.Fn timer_settime 2225507a2aeSRuslan Ermilovsystem call may fail if: 223bb5eebe6SDavid Xu.Bl -tag -width Er 224bb5eebe6SDavid Xu.It Bq Er EINVAL 2255507a2aeSRuslan ErmilovThe 2265507a2aeSRuslan Ermilov.Va it_interval 2275507a2aeSRuslan Ermilovmember of 2285507a2aeSRuslan Ermilov.Fa value 2295507a2aeSRuslan Ermilovis not zero and the timer was created with 2305507a2aeSRuslan Ermilovnotification by creation of a new thread 2315507a2aeSRuslan Ermilov.Va ( sigev_sigev_notify 2325507a2aeSRuslan Ermilovwas 2335507a2aeSRuslan Ermilov.Dv SIGEV_THREAD ) 234bb5eebe6SDavid Xuand a fixed stack address has been set in the thread attribute pointed to by 2355507a2aeSRuslan Ermilov.Va sigev_notify_attributes . 236bb5eebe6SDavid Xu.El 237bb5eebe6SDavid Xu.Pp 238bb5eebe6SDavid XuThe 239bb5eebe6SDavid Xu.Fn timer_gettime 240bb5eebe6SDavid Xuand 241bb5eebe6SDavid Xu.Fn timer_settime 2425507a2aeSRuslan Ermilovsystem calls 243bb5eebe6SDavid Xumay fail if: 244bb5eebe6SDavid Xu.Bl -tag -width Er 245bb5eebe6SDavid Xu.It Bq Er EFAULT 246bb5eebe6SDavid XuAny arguments point outside the allocated address space or there is a 247bb5eebe6SDavid Xumemory protection fault. 248bb5eebe6SDavid Xu.El 249bb5eebe6SDavid Xu.Sh SEE ALSO 250bb5eebe6SDavid Xu.Xr clock_getres 2 , 251412295fdSDavid Xu.Xr timer_create 2 , 252412295fdSDavid Xu.Xr siginfo 3 253bb5eebe6SDavid Xu.Sh STANDARDS 254bb5eebe6SDavid XuThe 255bb5eebe6SDavid Xu.Fn timer_getoverrun , 256bb5eebe6SDavid Xu.Fn timer_gettime , 257bb5eebe6SDavid Xuand 258bb5eebe6SDavid Xu.Fn timer_settime 2595507a2aeSRuslan Ermilovsystem calls conform to 260*9f63b422SGlen Barber.St -p1003.1-2004 . 2616f59c4c0SDavid Xu.Sh HISTORY 262a73a3ab5SRuslan ErmilovSupport for 263a73a3ab5SRuslan Ermilov.Tn POSIX 264a73a3ab5SRuslan Ermilovper-process timer first appeared in 2656f59c4c0SDavid Xu.Fx 7.0 . 266