getitimer(2) System Calls Manual getitimer(2) getitimer, setitimer - LIBRARY Standard C library (libc, -lc) #include int getitimer(int which, struct itimerval *curr_value); int setitimer(int which, const struct itimerval *restrict new_value, struct itimerval *_Nullable restrict old_value); , , , () . , ( ). Three types of timers--specified via the which argument--are provided, each of which counts against a different clock and generates a different signal on timer expiration: ITIMER_REAL ( ). SIGALRM. ITIMER_VIRTUAL , ( , ). SIGVTALRM. ITIMER_PROF , ( , ). SIGPROF. ITIMER_VIRTUAL . . , , : struct itimerval { struct timeval it_interval; /* Interval for periodic timer */ struct timeval it_value; /* Time until next expiration */ }; struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* microseconds */ }; getitimer() getitimer() , which, , curr_value. it_value . it_interval . it_value , (). it_interval . it_interval , ( ). setitimer() setitimer() which new_value. old_value NULL, , (. ., , getitimer()). - new_value.it_value , . new_value.it_value , . new_value.it_interval ; , . On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error. EFAULT new_value, old_value curr_value . EINVAL which is not one of ITIMER_REAL, ITIMER_VIRTUAL, or ITIMER_PROF; or (since Linux 2.6.22) one of the tv_usec fields in the structure pointed to by new_value contains a value outside the range [0, 999999]. : setitimer(which, NULL, &old_value); (Solaris, BSD , , ) : getitimer(which, &old_value); Linux , new_value 0, . Linux: . POSIX.1-2008. POSIX.1-2001, SVr4, 4.4BSD ( 4.2BSD). POSIX.1-2008 getitimer() setitimer() , POSIX (timer_gettime(2), timer_settime(2) ..). , (-) , ; time(7) ( ). (, ITIMER_VIRTUAL), . , fork(2), . execve(2) . POSIX.1 setitimer() : alarm(2), sleep(3) usleep(3). , , , . , ITIMER_REAL . . Before Linux 2.6.16, timer values are represented in jiffies. If a request is made set a timer with a value whose jiffies representation exceeds MAX_SEC_IN_JIFFIES (defined in include/linux/jiffies.h), then the timer is silently truncated to this ceiling value. On Linux/i386 (where, since Linux 2.6.13, the default jiffy is 0.004 seconds), this means that the ceiling value for a timer is approximately 99.42 days. Since Linux 2.6.16, the kernel uses a different internal representation for times, and this ceiling is removed. On certain systems (including i386), Linux kernels before Linux 2.6.12 have a bug which will produce premature timer expirations of up to one jiffy under some circumstances. This bug is fixed in Linux 2.6.12. POSIX.1-2001 says that setitimer() should fail if a tv_usec value is specified that is outside of the range [0, 999999]. However, up to and including Linux 2.6.21, Linux does not give an error, but instead silently adjusts the corresponding seconds value for the timer. From Linux 2.6.22 onward, this nonconformance has been repaired: an improper tv_usec value results in an EINVAL error. . gettimeofday(2), sigaction(2), signal(2), timer_create(2), timerfd_create(2), time(7) Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . getitimer(2)