{"id":5037,"date":"2022-12-20T18:37:04","date_gmt":"2022-12-20T21:37:04","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/times-man3p\/"},"modified":"2022-12-20T18:37:04","modified_gmt":"2022-12-20T21:37:04","slug":"times-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/times-man3p\/","title":{"rendered":"TIMES (man3p)"},"content":{"rendered":"<h1 align=\"center\">TIMES<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">times \u2014 get process and waited-for child process times<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <sys\/times.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">clock_t times(struct tms *<i>buffer<\/i>);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>times<\/i>() function shall fill the <b>tms<\/b> structure pointed to by <i>buffer<\/i> with time-accounting information. The <b>tms<\/b> structure is defined in <i><sys\/times.h><\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">All times are measured in terms of the number of clock ticks used.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The times of a terminated child process shall be included in the <i>tms_cutime<\/i> and <i>tms_cstime<\/i> elements of the parent when <i>wait<\/i>(), <i>waitid<\/i>(), or <i>waitpid<\/i>() 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.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"2%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"83%\">\n<p>The <i>tms_utime<\/i> structure member is the CPU time charged for the execution of user instructions of the calling process.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"2%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"83%\">\n<p>The <i>tms_stime<\/i> structure member is the CPU time charged for execution by the system on behalf of the calling process.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"2%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"83%\">\n<p>The <i>tms_cutime<\/i> structure member is the sum of the <i>tms_utime<\/i> and <i>tms_cutime<\/i> times of the child processes.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"2%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"83%\">\n<p>The <i>tms_cstime<\/i> structure member is the sum of the <i>tms_stime<\/i> and <i>tms_cstime<\/i> times of the child processes.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>times<\/i>() 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 <i>times<\/i>() within the process to another. The return value may overflow the possible range of type <b>clock_t<\/b>. If <i>times<\/i>() fails, (<b>clock_t<\/b>)\u22121 shall be returned and <i>errno<\/i> set to indicate the error.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>times<\/i>() function shall fail if: <b><br \/> EOVERFLOW<\/b><\/p>\n<p style=\"margin-left:22%;\">The return value would overflow the range of <b>clock_t<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i><b>Timing a Database Lookup<\/b><\/i> <br \/> The following example defines two functions, <i>start_clock<\/i>() and <i>end_clock<\/i>(), that are used to time a lookup. It also defines variables of type <b>clock_t<\/b> and <b>tms<\/b> to measure the duration of transactions. The <i>start_clock<\/i>() function saves the beginning times given by the <i>times<\/i>() function. The <i>end_clock<\/i>() function gets the ending times and prints the difference between the two times.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <sys\/times.h> <br \/> #include <stdio.h> <br \/> &#8230; <br \/> void start_clock(void); <br \/> void end_clock(char *msg); <br \/> &#8230; <br \/> static clock_t st_time; <br \/> static clock_t en_time; <br \/> static struct tms st_cpu; <br \/> static struct tms en_cpu; <br \/> &#8230; <br \/> void <br \/> start_clock() <br \/> { <br \/> st_time = times(&#038;st_cpu); <br \/> }<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">\/* This example assumes that the result of each subtraction <br \/> is within the range of values that can be represented in <br \/> an integer type. bodies\/ usr\/ <br \/> void <br \/> end_clock(char *msg) <br \/> { <br \/> en_time = times(&#038;en_cpu);<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">fputs(msg,stdout); <br \/> printf(&#8220;Real Time: %jd, User Time %jd, System Time %jdn&#8221;, <br \/> (intmax_t)(en_time &#8211; st_time), <br \/> (intmax_t)(en_cpu.tms_utime &#8211; st_cpu.tms_utime), <br \/> (intmax_t)(en_cpu.tms_stime &#8211; st_cpu.tms_stime)); <br \/> }<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Applications should use <i>sysconf<\/i>(_SC_CLK_TCK) to determine the number of clock ticks per second as it may vary from system to system.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The accuracy of the times reported is intentionally left unspecified to allow implementations flexibility in design, from uniprocessor to multi-processor networks.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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 \u2018\u2018realtime\u2019\u2019 in <i>alarm<\/i>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the type <b>clock_t<\/b> 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-2017 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.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The term \u2018\u2018charge\u2019\u2019 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.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>alarm<\/i>(), <i>exec<\/i>, <i>fork<\/i>(), <i>sysconf<\/i>(), <i>time<\/i>(), <i>wait<\/i>(), <i>waitid<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <b><sys_times.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; 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 .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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 .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  times \u2014 get process and waited-for child process times <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[1594,1931],"class_list":["post-5037","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-man3p","tag-times"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5037"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5037\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}