GETITIMER(3POSIX)

πŸ’– GETITIMER(3POSIX) πŸ’–

okay bestie, welcome to the POSIX Programmer's Manual β€” this is the getitimer page, and we're gonna get into it. 🫢


🌸 PROLOG 🌸

so like, real talk first: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (if you're on Linux, go check the corresponding Linux manual page for the actual tea β˜•), or honestly the interface might not even be implemented on Linux at all. πŸ™ˆ


✨ NAME ✨

getitimer, setitimer β€” get and set value of interval timer. it's giving "clock management, but make it POSIX." πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/time.h>

int getitimer(int which, struct itimerval *value);
int setitimer(int which, const struct itimerval *restrict value,
    struct itimerval *restrict ovalue);

πŸ’œ DESCRIPTION πŸ’œ

so the getitimer() function shall store the current value of the timer specified by which into the structure pointed to by value. simple. iconic. no notes. ✨

and setitimer()? it shall set the timer specified by which to the value specified in the structure pointed to by value, and β€” plot twist β€” if ovalue is not a null pointer, it stores the previous value of the timer in the structure pointed to by ovalue. so you get the receipts of what it was before. πŸ§ΎπŸ’…

A timer value is defined by the itimerval structure, specified in <sys/time.h>. here's the breakdown:

  • if it_value is non-zero, it shall indicate the time to the next timer expiration. ⏰
  • if it_interval is non-zero, it shall specify a value to be used in reloading it_value when the timer expires. πŸ”
  • setting it_value to 0 shall disable a timer, regardless of the value of it_interval. (yes, regardless. it_value is the main character here πŸ‘‘)
  • setting it_interval to 0 shall disable a timer after its next expiration (assuming it_value is non-zero). so it gets one last hurrah. 🎀

Implementations may place limitations on the granularity of timer values. For each interval timer, if the requested timer value requires a finer granularity than the implementation supports, the actual timer value shall be rounded up to the next supported value. so like, you ask for something tiny and precise, and the system rounds up. no down-rounding, bestie. πŸ“ˆ

An XSI-conforming implementation provides each process with at least three interval timers, which are indicated by the which argument:

  • ITIMER_PROF β€” Decrements both in process virtual time and when the system is running on behalf of the process. It is designed to be used by interpreters in statistically profiling the execution of interpreted programs. Each time the ITIMER_PROF timer expires, the SIGPROF signal is delivered. πŸ“Š
  • ITIMER_REAL β€” Decrements in real time. A SIGALRM signal is delivered when this timer expires. ⏱️
  • ITIMER_VIRTUAL β€” Decrements in process virtual time. It runs only when the process is executing. A SIGVTALRM signal is delivered when it expires. 🧠
⚠️ okay warning time: the interaction between setitimer() and alarm() or sleep() is unspecified. so like, don't expect them to play nice together, bestie. that's undefined territory. πŸ’€

πŸ”₯ RETURN VALUE πŸ”₯

Upon successful completion, getitimer() or setitimer() shall return 0. πŸŽ‰

otherwise, -1 shall be returned and errno set to indicate the error. 😭


πŸ’… ERRORS πŸ’…

The setitimer() function shall fail if:

  • EINVAL β€” The value argument is not in canonical form. (In canonical form, the number of microseconds is a non-negative integer less than 1000000 and the number of seconds is a non-negative integer.) like, get that struct in canonical form or it's not happening. 🚫

The getitimer() and setitimer() functions may fail if:

  • EINVAL β€” The which argument is not recognized. (unknown timer? not on my watch. πŸ‘€)

The following sections are informative.


🌈 EXAMPLES 🌈

None.

(yeah. nothing. the vibes are immaculate but empty. πŸƒ)


πŸ¦‹ APPLICATION USAGE πŸ¦‹

Applications should use the timer_gettime() and timer_settime() functions instead of the obsolescent getitimer() and setitimer() functions, respectively. πŸ“’ like bestie, these two are obsolescent β€” there's a newer, shinier way. use that instead, fr fr.


⭐ RATIONALE ⭐

None.


πŸ‘‘ FUTURE DIRECTIONS πŸ‘‘

The getitimer() and setitimer() functions may be removed in a future version. so like... don't build your whole personality around them, iykyk. πŸ’€


πŸŽ€ SEE ALSO πŸŽ€

  • alarm()
  • exec
  • sleep()
  • timer_getoverrun()

The Base Definitions volume of POSIX.1‐2017, <signal.h>, <sys_time.h>


Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay that's the whole page bestie, you ate that 🫢✨ this was IEEE/The Open Group, 2017, page GETITIMER(3POSIX) β€” and that's a wrap, periodt. πŸ’…πŸ’–