isposix

Un outil pour savoir si une commande est posix - retour accueil

git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |

time.html (19526B)


      1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved -->
      2 <!DOCTYPE HTML>
      3 <html lang="en">
      4 <head>
      5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0">
      6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 -->
      8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved -->
      9 <title>time</title>
     10 </head>
     11 <body bgcolor="white">
     12 <div class="NAVHEADER">
     13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
     14 <tr class="nav">
     15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/test.html" accesskey="P">&lt;&lt;&lt;
     16 Previous</a></td>
     17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
     18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/timeout.html" accesskey="N">Next
     19 &gt;&gt;&gt;</a></td>
     20 </tr>
     21 </table>
     22 <hr align="left" width="100%"></div>
     23 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3">
     24 <center><font size="2">The Open Group Base Specifications Issue 8<br>
     25 IEEE Std 1003.1-2024<br>
     26 Copyright © 2001-2024 The IEEE and The Open Group</font></center>
     27 <hr size="2" noshade>
     28 <a name="top" id="top"></a> <a name="time" id="time"></a> <a name="tag_20_122" id="tag_20_122"></a><!-- time -->
     29 <h4 class="mansect"><a name="tag_20_122_01" id="tag_20_122_01"></a>NAME</h4>
     30 <blockquote>time — time a simple command</blockquote>
     31 <h4 class="mansect"><a name="tag_20_122_02" id="tag_20_122_02"></a>SYNOPSIS</h4>
     32 <blockquote class="synopsis">
     33 <p><code><tt>time</tt> <b>[</b><tt>-p</tt><b>]</b> <i>utility</i> <b>[</b><i>argument</i><tt>...</tt><b>]</b></code></p>
     34 </blockquote>
     35 <h4 class="mansect"><a name="tag_20_122_03" id="tag_20_122_03"></a>DESCRIPTION</h4>
     36 <blockquote>
     37 <p>The <i>time</i> utility shall invoke the utility named by the <i>utility</i> operand with arguments supplied as the
     38 <i>argument</i> operands and write a message to standard error that lists timing statistics for the utility. The message shall
     39 include the following information:</p>
     40 <ul>
     41 <li>
     42 <p>The elapsed (real) time between invocation of <i>utility</i> and its termination.</p>
     43 </li>
     44 <li>
     45 <p>The User CPU time, equivalent to the sum of the <i>tms_utime</i> and <i>tms_cutime</i> fields returned by the <a href=
     46 "../functions/times.html"><i>times</i>()</a> function defined in the System Interfaces volume of POSIX.1-2024 for the process in
     47 which <i>utility</i> is executed.</p>
     48 </li>
     49 <li>
     50 <p>The System CPU time, equivalent to the sum of the <i>tms_stime</i> and <i>tms_cstime</i> fields returned by the <a href=
     51 "../functions/times.html"><i>times</i>()</a> function for the process in which <i>utility</i> is executed.</p>
     52 </li>
     53 </ul>
     54 <p>The precision of the timing shall be no less than the granularity defined for the size of the clock tick unit on the system, but
     55 the results shall be reported in terms of standard time units (for example, 0.02 seconds, 00:00:00.02, 1m33.75s, 365.21 seconds),
     56 not numbers of clock ticks.</p>
     57 <p>When <i>time</i> is used in any of the following circumstances, via a simple command for which the word <b>time</b> is the
     58 command name (see <a href="../utilities/V3_chap02.html#tag_19_09_01_01"><i>2.9.1.1 Order of Processing</i></a> ), and none of the
     59 characters in the word <b>time</b> is quoted, the results (including parsing of later words) are unspecified:</p>
     60 <ul>
     61 <li>
     62 <p>The simple command for which the word <b>time</b> is the command name includes one or more redirections (see <a href=
     63 "../utilities/V3_chap02.html#tag_19_07"><i>2.7 Redirection</i></a> ) or is (directly) part of a pipeline (see <a href=
     64 "../utilities/V3_chap02.html#tag_19_09_02"><i>2.9.2 Pipelines</i></a> ).</p>
     65 </li>
     66 <li>
     67 <p>The next word that follows <b>time</b> would, if the word <b>time</b> were not present, be recognized as a reserved word (see
     68 <a href="../utilities/V3_chap02.html#tag_19_04"><i>2.4 Reserved Words</i></a> ) or a control operator (see XBD <a href=
     69 "../basedefs/V1_chap03.html#tag_03_85"><i>3.85 Control Operator</i></a> ).</p>
     70 </li>
     71 </ul>
     72 <p>Since these limitations only apply when <i>time</i> is executed via a simple command for which the word <b>time</b> is the
     73 command name and none of the characters in the word <b>time</b> is quoted, they can be avoided by quoting all or part of the word
     74 <b>time</b>, by arranging for the command name not to be <b>time</b> (for example, by having the command name be a word expansion),
     75 or by executing <i>time</i> via another utility such as <a href="../utilities/command.html"><i>command</i></a> or <a href=
     76 "../utilities/env.html"><i>env</i></a>.</p>
     77 <p>The limitations on redirections and pipelines can also be overcome by embedding the simple command within a compound
     78 command—most commonly a grouping command (see <a href="../utilities/V3_chap02.html#tag_19_09_04_01"><i>2.9.4.1 Grouping
     79 Commands</i></a> )—and applying the redirections or piping to the compound command instead.</p>
     80 <p>Note that in no circumstances where the results are specified is it possible to apply different redirections to the <i>time</i>
     81 utility than are applied to the utility it invokes.</p>
     82 <p>The following examples (where <i>a</i> and <i>b</i> are assumed to be the names of utilities found by searching <i>PATH )</i>
     83 show unspecified usages:</p>
     84 <pre>
     85 <tt>time a arg1 arg2 | b    # part of a pipeline
     86 a | time -p b           # part of a pipeline
     87 time a &gt;/dev/null       # output redirection
     88 &lt;/dev/null time a       # input redirection
     89 time while anything...  # reserved word after time
     90 time ( cmd )            # control operator after time
     91 time;                   # control operator after time
     92 time shift              # special built-in utility
     93 time -p cd /            # intrinsic utility
     94 </tt></pre>
     95 <p>The following examples have specified results and can be used as alternatives for the first four of the above when the
     96 <i>time</i> utility as specified here is intended to be invoked:</p>
     97 <pre>
     98 <tt>{ time a arg1 arg2; } | b
     99 t=time; a | $t -p b
    100 command time a &gt;/dev/null
    101 &lt;/dev/null \time a
    102 </tt></pre></blockquote>
    103 <h4 class="mansect"><a name="tag_20_122_04" id="tag_20_122_04"></a>OPTIONS</h4>
    104 <blockquote>
    105 <p>The <i>time</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax
    106 Guidelines</i></a> .</p>
    107 <p>The following option shall be supported:</p>
    108 <dl compact>
    109 <dd></dd>
    110 <dt><b>-p</b></dt>
    111 <dd>Write the timing output to standard error in the format shown in the STDERR section.</dd>
    112 </dl>
    113 </blockquote>
    114 <h4 class="mansect"><a name="tag_20_122_05" id="tag_20_122_05"></a>OPERANDS</h4>
    115 <blockquote>
    116 <p>The following operands shall be supported:</p>
    117 <dl compact>
    118 <dd></dd>
    119 <dt><i>utility</i></dt>
    120 <dd>The name of a utility that is to be invoked. If the <i>utility</i> operand names a special built-in utility (see <a href=
    121 "../utilities/V3_chap02.html#tag_19_15"><i>2.15 Special Built-In Utilities</i></a> ), an intrinsic utility (see <a href=
    122 "../utilities/V3_chap01.html#tag_18_07"><i>1.7 Intrinsic Utilities</i></a> ), or a function (see <a href=
    123 "../utilities/V3_chap02.html#tag_19_09_05"><i>2.9.5 Function Definition Command</i></a> ), the results are unspecified.</dd>
    124 <dt><i>argument</i></dt>
    125 <dd>Any string to be supplied as an argument when invoking the utility named by the <i>utility</i> operand.</dd>
    126 </dl>
    127 </blockquote>
    128 <h4 class="mansect"><a name="tag_20_122_06" id="tag_20_122_06"></a>STDIN</h4>
    129 <blockquote>
    130 <p>Not used.</p>
    131 </blockquote>
    132 <h4 class="mansect"><a name="tag_20_122_07" id="tag_20_122_07"></a>INPUT FILES</h4>
    133 <blockquote>
    134 <p>None.</p>
    135 </blockquote>
    136 <h4 class="mansect"><a name="tag_20_122_08" id="tag_20_122_08"></a>ENVIRONMENT VARIABLES</h4>
    137 <blockquote>
    138 <p>The following environment variables shall affect the execution of <i>time</i>:</p>
    139 <dl compact>
    140 <dd></dd>
    141 <dt><i>LANG</i></dt>
    142 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href=
    143 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization
    144 variables used to determine the values of locale categories.)</dd>
    145 <dt><i>LC_ALL</i></dt>
    146 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
    147 <dt><i>LC_CTYPE</i></dt>
    148 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
    149 opposed to multi-byte characters in arguments).</dd>
    150 <dt><i>LC_MESSAGES</i></dt>
    151 <dd><br>
    152 Determine the locale that should be used to affect the format and contents of diagnostic and informative messages written to
    153 standard error.</dd>
    154 <dt><i>LC_NUMERIC</i></dt>
    155 <dd><br>
    156 Determine the locale for numeric formatting.</dd>
    157 <dt><i>NLSPATH</i></dt>
    158 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
    159 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border=
    160 "0"></dd>
    161 <dt><i>PATH</i></dt>
    162 <dd>Determine the search path that shall be used to locate the utility to be invoked; see XBD <a href=
    163 "../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> .</dd>
    164 </dl>
    165 </blockquote>
    166 <h4 class="mansect"><a name="tag_20_122_09" id="tag_20_122_09"></a>ASYNCHRONOUS EVENTS</h4>
    167 <blockquote>
    168 <p>Default.</p>
    169 </blockquote>
    170 <h4 class="mansect"><a name="tag_20_122_10" id="tag_20_122_10"></a>STDOUT</h4>
    171 <blockquote>
    172 <p>Not used.</p>
    173 </blockquote>
    174 <h4 class="mansect"><a name="tag_20_122_11" id="tag_20_122_11"></a>STDERR</h4>
    175 <blockquote>
    176 <p>If the <i>utility</i> utility is invoked, the standard error shall be used to write the timing statistics and may be used to
    177 write a diagnostic message if the utility terminates abnormally; otherwise, the standard error shall be used to write diagnostic
    178 messages and may also be used to write the timing statistics.</p>
    179 <p>If <b>-p</b> is specified, the following format shall be used for the timing statistics in the POSIX locale:</p>
    180 <pre>
    181 <tt>"real %f\nuser %f\nsys %f\n", &lt;</tt><i>real seconds</i><tt>&gt;, &lt;</tt><i>user seconds</i><tt>&gt;,
    182     &lt;</tt><i>system seconds</i><tt>&gt;
    183 </tt></pre>
    184 <p>where each floating-point number shall be expressed in seconds. The precision used may be less than the default six digits of
    185 <tt>%f</tt>, but shall be sufficiently precise to accommodate the size of the clock tick on the system (for example, if there were
    186 60 clock ticks per second, at least two digits shall follow the radix character). The number of digits following the radix
    187 character shall be no less than one, even if this always results in a trailing zero. The implementation may append white space and
    188 additional information following the format shown here. The implementation may also prepend a single empty line before the format
    189 shown here.</p>
    190 </blockquote>
    191 <h4 class="mansect"><a name="tag_20_122_12" id="tag_20_122_12"></a>OUTPUT FILES</h4>
    192 <blockquote>
    193 <p>None.</p>
    194 </blockquote>
    195 <h4 class="mansect"><a name="tag_20_122_13" id="tag_20_122_13"></a>EXTENDED DESCRIPTION</h4>
    196 <blockquote>
    197 <p>None.</p>
    198 </blockquote>
    199 <h4 class="mansect"><a name="tag_20_122_14" id="tag_20_122_14"></a>EXIT STATUS</h4>
    200 <blockquote>
    201 <p>If the <i>utility</i> utility is invoked, the exit status of <i>time</i> shall be the exit status of <i>utility</i>; otherwise,
    202 the <i>time</i> utility shall exit with one of the following values:</p>
    203 <dl compact>
    204 <dd></dd>
    205 <dt>1-125</dt>
    206 <dd>An error occurred in the <i>time</i> utility.</dd>
    207 <dt>&nbsp;&nbsp;126</dt>
    208 <dd>The utility specified by <i>utility</i> was found but could not be invoked.</dd>
    209 <dt>&nbsp;&nbsp;127</dt>
    210 <dd>The utility specified by <i>utility</i> could not be found.</dd>
    211 </dl>
    212 </blockquote>
    213 <h4 class="mansect"><a name="tag_20_122_15" id="tag_20_122_15"></a>CONSEQUENCES OF ERRORS</h4>
    214 <blockquote>
    215 <p>Default.</p>
    216 </blockquote>
    217 <hr>
    218 <div class="box"><em>The following sections are informative.</em></div>
    219 <h4 class="mansect"><a name="tag_20_122_16" id="tag_20_122_16"></a>APPLICATION USAGE</h4>
    220 <blockquote>
    221 <p>The <a href="../utilities/command.html"><i>command</i></a>, <a href="../utilities/env.html"><i>env</i></a>, <a href=
    222 "../utilities/nice.html"><i>nice</i></a>, <a href="../utilities/nohup.html"><i>nohup</i></a>, <i>time</i>, <a href=
    223 "../utilities/timeout.html"><i>timeout</i></a>, and <a href="../utilities/xargs.html"><i>xargs</i></a> utilities have been
    224 specified to use exit code 127 if a utility to be invoked cannot be found, so that applications can distinguish &quot;failure to find a
    225 utility&quot; from &quot;invoked utility exited with an error indication&quot;. The value 127 was chosen because it is not commonly used for
    226 other meanings; most utilities use small values for &quot;normal error conditions&quot; and the values above 128 can be confused with
    227 termination due to receipt of a signal. The value 126 was chosen in a similar manner to indicate that the utility could be found,
    228 but not invoked. Some scripts produce meaningful error messages differentiating the 126 and 127 cases. The distinction between exit
    229 codes 126 and 127 is based on KornShell practice that uses 127 when all attempts to <i>exec</i> the utility fail with [ENOENT], and
    230 uses 126 when any attempt to <i>exec</i> the utility fails for any other reason.</p>
    231 </blockquote>
    232 <h4 class="mansect"><a name="tag_20_122_17" id="tag_20_122_17"></a>EXAMPLES</h4>
    233 <blockquote>
    234 <p>It is frequently desirable to apply <i>time</i> to pipelines or lists of commands. This can be done by placing pipelines and
    235 command lists in a single file; this file can then be invoked as a utility, and the <i>time</i> applies to everything in the
    236 file.</p>
    237 <p>Alternatively, the following command can be used to apply <i>time</i> to a complex command:</p>
    238 <pre>
    239 <tt>time sh -c -- '</tt><i>complex-command-line</i><tt>'
    240 </tt></pre></blockquote>
    241 <h4 class="mansect"><a name="tag_20_122_18" id="tag_20_122_18"></a>RATIONALE</h4>
    242 <blockquote>
    243 <p>When the <i>time</i> utility was originally proposed to be included in the ISO&nbsp;POSIX-2:1993 standard, questions were raised
    244 about its suitability for inclusion on the grounds that it was not useful for conforming applications, specifically:</p>
    245 <ul>
    246 <li>
    247 <p>The underlying CPU definitions from the System Interfaces volume of POSIX.1-2024 are vague, so the numeric output could not be
    248 compared accurately between systems or even between invocations.</p>
    249 </li>
    250 <li>
    251 <p>The creation of portable benchmark programs was outside the scope this volume of POSIX.1-2024.</p>
    252 </li>
    253 </ul>
    254 <p>However, <i>time</i> does fit in the scope of user portability. Human judgement can be applied to the analysis of the output,
    255 and it could be very useful in hands-on debugging of applications or in providing subjective measures of system performance. Hence
    256 it has been included in this volume of POSIX.1-2024.</p>
    257 <p>The default output format has been left unspecified because historical implementations differ greatly in their style of
    258 depicting this numeric output. The <b>-p</b> option was invented to provide scripts with a common means of obtaining this
    259 information.</p>
    260 <p>In the KornShell, <i>time</i> is a shell reserved word that can be used to time an entire pipeline, rather than just a simple
    261 command. The POSIX definition has been worded to allow this implementation. Consideration was given to invalidating this approach
    262 because of the historical model from the C shell and System V shell. However, since the System V <i>time</i> utility historically
    263 has not produced accurate results in pipeline timing (because the constituent processes are not all owned by the same parent
    264 process, as allowed by POSIX), it did not seem worthwhile to break historical KornShell usage.</p>
    265 <p>The term <i>utility</i> is used, rather than <i>command</i>, to highlight the fact that shell compound commands, pipelines,
    266 special built-ins, and so on, cannot be used directly. However, <i>utility</i> includes user application programs and shell
    267 scripts, not just the standard utilities.</p>
    268 </blockquote>
    269 <h4 class="mansect"><a name="tag_20_122_19" id="tag_20_122_19"></a>FUTURE DIRECTIONS</h4>
    270 <blockquote>
    271 <p>None.</p>
    272 </blockquote>
    273 <h4 class="mansect"><a name="tag_20_122_20" id="tag_20_122_20"></a>SEE ALSO</h4>
    274 <blockquote>
    275 <p><a href="../utilities/V3_chap02.html#tag_19"><i>2. Shell Command Language</i></a> , <a href=
    276 "../utilities/sh.html#"><i>sh</i></a></p>
    277 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href=
    278 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p>
    279 <p>XSH <a href="../functions/times.html#tag_17_629"><i>times</i></a></p>
    280 </blockquote>
    281 <h4 class="mansect"><a name="tag_20_122_21" id="tag_20_122_21"></a>CHANGE HISTORY</h4>
    282 <blockquote>
    283 <p>First released in Issue 2.</p>
    284 </blockquote>
    285 <h4 class="mansect"><a name="tag_20_122_22" id="tag_20_122_22"></a>Issue 6</h4>
    286 <blockquote>
    287 <p>This utility is marked as part of the User Portability Utilities option.</p>
    288 </blockquote>
    289 <h4 class="mansect"><a name="tag_20_122_23" id="tag_20_122_23"></a>Issue 7</h4>
    290 <blockquote>
    291 <p>The <i>time</i> utility is moved from the User Portability Utilities option to the Base. User Portability Utilities is now an
    292 option for interactive utilities.</p>
    293 <p>SD5-XCU-ERN-115 is applied, updating the example in the DESCRIPTION.</p>
    294 <p>POSIX.1-2008, Technical Corrigendum 1, XCU/TC1-2008/0144 [266] is applied.</p>
    295 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0194 [723] is applied.</p>
    296 </blockquote>
    297 <h4 class="mansect"><a name="tag_20_122_24" id="tag_20_122_24"></a>Issue 8</h4>
    298 <blockquote>
    299 <p>Austin Group Defect 267 is applied, allowing <b>time</b> to be a reserved word.</p>
    300 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p>
    301 <p>Austin Group Defect 1530 is applied, changing &quot;<tt>sh -c</tt>&quot; to &quot;<tt>sh -c --</tt>&quot;.</p>
    302 <p>Austin Group Defect 1586 is applied, adding the <a href="../utilities/timeout.html"><i>timeout</i></a> utility.</p>
    303 <p>Austin Group Defect 1594 is applied, changing the APPLICATION USAGE section.</p>
    304 </blockquote>
    305 <div class="box"><em>End of informative text.</em></div>
    306 <hr>
    307 <p>&nbsp;</p>
    308 <a href="#top"><span class="topOfPage">return to top of page</span></a><br>
    309 <hr size="2" noshade>
    310 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br>
    311 POSIX™ is a Trademark of The IEEE.<br>
    312 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br>
    313 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
    314 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a>
    315 ]</font></center>
    316 <hr size="2" noshade>
    317 <div class="NAVHEADER">
    318 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0">
    319 <tr class="nav">
    320 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/test.html" accesskey="P">&lt;&lt;&lt;
    321 Previous</a></td>
    322 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td>
    323 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/timeout.html" accesskey="N">Next
    324 &gt;&gt;&gt;</a></td>
    325 </tr>
    326 </table>
    327 <hr align="left" width="100%"></div>
    328 </body>
    329 </html>