TIMES(3)                   POSIX Programmer's Manual                  TIMES(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       times -- get process and waited-for child process times

SSYYNNOOPPSSIISS
       #include <sys/times.h>

       clock_t times(struct tms *_b_u_f_f_e_r);

DDEESSCCRRIIPPTTIIOONN
       The _t_i_m_e_s() function shall fill the ttmmss structure pointed to by _b_u_f_f_e_r
       with time-accounting information. The ttmmss structure is defined in
       _<_s_y_s_/_t_i_m_e_s_._h_>.

       All times are measured in terms of the number of clock ticks used.

       The times of a terminated child process shall be included in the
       _t_m_s___c_u_t_i_m_e and _t_m_s___c_s_t_i_m_e elements of the parent when _w_a_i_t(), _w_a_i_t_i_d(),
       or _w_a_i_t_p_i_d() returns the process ID of this terminated child. If a
       child process has not waited for its children, their times shall not be
       included in its times.

        *  The _t_m_s___u_t_i_m_e structure member is the CPU time charged for the
           execution of user instructions of the calling process.

        *  The _t_m_s___s_t_i_m_e structure member is the CPU time charged for
           execution by the system on behalf of the calling process.

        *  The _t_m_s___c_u_t_i_m_e structure member is the sum of the _t_m_s___u_t_i_m_e and
           _t_m_s___c_u_t_i_m_e times of the child processes.

        *  The _t_m_s___c_s_t_i_m_e structure member is the sum of the _t_m_s___s_t_i_m_e and
           _t_m_s___c_s_t_i_m_e times of the child processes.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _t_i_m_e_s() shall return the elapsed real time,
       in clock ticks, since an arbitrary point in the past (for example,
       system start-up time). This point does not change from one invocation
       of _t_i_m_e_s() within the process to another. The return value may overflow
       the possible range of type cclloocckk__tt.  If _t_i_m_e_s() fails, (cclloocckk__tt)-1
       shall be returned and _e_r_r_n_o set to indicate the error.

EERRRROORRSS
       No errors are defined.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   TTiimmiinngg aa DDaattaabbaassee LLooookkuupp
       The following example defines two functions, _s_t_a_r_t___c_l_o_c_k() and
       _e_n_d___c_l_o_c_k(), that are used to time a lookup. It also defines variables
       of type cclloocckk__tt and ttmmss to measure the duration of transactions. The
       _s_t_a_r_t___c_l_o_c_k() function saves the beginning times given by the _t_i_m_e_s()
       function. The _e_n_d___c_l_o_c_k() function gets the ending times and prints the
       difference between the two times.

           ##iinncclluuddee <<ssyyss//ttiimmeess..hh>>
           ##iinncclluuddee <<ssttddiioo..hh>>
           ......
           vvooiidd ssttaarrtt__cclloocckk((vvooiidd));;
           vvooiidd eenndd__cclloocckk((cchhaarr **mmssgg));;
           ......
           ssttaattiicc cclloocckk__tt sstt__ttiimmee;;
           ssttaattiicc cclloocckk__tt eenn__ttiimmee;;
           ssttaattiicc ssttrruucctt ttmmss sstt__ccppuu;;
           ssttaattiicc ssttrruucctt ttmmss eenn__ccppuu;;
           ......
           vvooiidd
           ssttaarrtt__cclloocckk(())
           {{
               sstt__ttiimmee == ttiimmeess((&&sstt__ccppuu));;
           }}

           /* This example assumes that the result of each subtraction
              is within the range of values that can be represented in
              an integer type. */
           void
           end_clock(char *msg)
           {
               en_time = times(&en_cpu);

               fputs(msg,stdout);
               printf("Real Time: %jd, User Time %jd, System Time %jd\n",
                   (intmax_t)(en_time - st_time),
                   (intmax_t)(en_cpu.tms_utime - st_cpu.tms_utime),
                   (intmax_t)(en_cpu.tms_stime - st_cpu.tms_stime));
           }

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       Applications should use _s_y_s_c_o_n_f(_SC_CLK_TCK) to determine the number of
       clock ticks per second as it may vary from system to system.

RRAATTIIOONNAALLEE
       The accuracy of the times reported is intentionally left unspecified to
       allow implementations flexibility in design, from uniprocessor to
       multi-processor networks.

       The inclusion of times of child processes is recursive, so that a
       parent process may collect the total times of all of its descendants.
       But the times of a child are only added to those of its parent when its
       parent successfully waits on the child. Thus, it is not guaranteed that
       a parent process can always see the total times of all its descendants;
       see also the discussion of the term ``realtime'' in _a_l_a_r_m().

       If the type cclloocckk__tt is defined to be a signed 32-bit integer, it
       overflows in somewhat more than a year if there are 60 clock ticks per
       second, or less than a year if there are 100. There are individual
       systems that run continuously for longer than that. This volume of
       POSIX.1-2008 permits an implementation to make the reference point for
       the returned value be the start-up time of the process, rather than
       system start-up time.

       The term ``charge'' in this context has nothing to do with billing for
       services. The operating system accounts for time used in this way. That
       information must be correct, regardless of how that information is
       used.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _a_l_a_r_m(), _e_x_e_c, _f_o_r_k(), _s_y_s_c_o_n_f(), _t_i_m_e(), _w_a_i_t(), _w_a_i_t_i_d()

       The Base Definitions volume of POSIX.1-2008, <<ssyyss__ttiimmeess..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) 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.unix.org/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 .



IEEE/The Open Group                  2013                             TIMES(3)
