341 lines
13 KiB
HTML
341 lines
13 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>time</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="time"></a> <a name="tag_04_141"></a><!-- time -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_04_141_01"></a>NAME</h4>
|
|
|
|
<blockquote>time - time a simple command</blockquote>
|
|
|
|
<h4><a name="tag_04_141_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<div class="box"><code><tt><sup>[<a href="javascript:open_code('UP')">UP</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> time</tt> <b>[</b><tt>-p</tt><b>]</b> <i>utility</i>
|
|
<b>[</b><i>argument</i><tt>...</tt><b>]</b><tt><img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>time</i> utility shall invoke the utility named by the <i>utility</i> operand with arguments supplied as the
|
|
<i>argument</i> operands and write a message to standard error that lists timing statistics for the utility. The message shall
|
|
include the following information:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The elapsed (real) time between invocation of <i>utility</i> and its termination.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<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=
|
|
"../functions/times.html"><i>times</i>()</a> function defined in the System Interfaces volume of IEEE Std 1003.1-2001 for
|
|
the process in which <i>utility</i> is executed.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<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=
|
|
"../functions/times.html"><i>times</i>()</a> function for the process in which <i>utility</i> is executed.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<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
|
|
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),
|
|
not numbers of clock ticks.</p>
|
|
|
|
<p>When <i>time</i> is used as part of a pipeline, the times reported are unspecified, except when it is the sole command within a
|
|
grouping command (see <a href="xcu_chap02.html#tag_02_09_04_01"><i>Grouping Commands</i></a> ) in that pipeline. For example, the
|
|
commands on the left are unspecified; those on the right report on utilities <b>a</b> and <b>c</b>, respectively:</p>
|
|
|
|
<pre>
|
|
<tt>time a | b | c { time a } | b | c
|
|
a | b | time c a | b | (time c)
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_04"></a>OPTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>time</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
|
|
|
|
<p>The following option shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><b>-p</b></dt>
|
|
|
|
<dd>Write the timing output to standard error in the format shown in the STDERR section.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_05"></a>OPERANDS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following operands shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>utility</i></dt>
|
|
|
|
<dd>The name of a utility that is to be invoked. If the <i>utility</i> operand names any of the special built-in utilities in <a
|
|
href="xcu_chap02.html#tag_02_14"><i>Special Built-In Utilities</i></a> , the results are undefined.</dd>
|
|
|
|
<dt><i>argument</i></dt>
|
|
|
|
<dd>Any string to be supplied as an argument when invoking the utility named by the <i>utility</i> operand.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_06"></a>STDIN</h4>
|
|
|
|
<blockquote>
|
|
<p>Not used.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_07"></a>INPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_08"></a>ENVIRONMENT VARIABLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following environment variables shall affect the execution of <i>time</i>:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>LANG</i></dt>
|
|
|
|
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
|
|
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
|
|
|
|
<dt><i>LC_ALL</i></dt>
|
|
|
|
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
|
|
|
|
<dt><i>LC_CTYPE</i></dt>
|
|
|
|
<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
|
|
opposed to multi-byte characters in arguments).</dd>
|
|
|
|
<dt><i>LC_MESSAGES</i></dt>
|
|
|
|
<dd>Determine the locale that should be used to affect the format and contents of diagnostic and informative messages written to
|
|
standard error.</dd>
|
|
|
|
<dt><i>LC_NUMERIC</i></dt>
|
|
|
|
<dd><br>
|
|
Determine the locale for numeric formatting.</dd>
|
|
|
|
<dt><i>NLSPATH</i></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
|
|
<dt><i>PATH</i></dt>
|
|
|
|
<dd>Determine the search path that shall be used to locate the utility to be invoked; see the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_09"></a>ASYNCHRONOUS EVENTS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_10"></a>STDOUT</h4>
|
|
|
|
<blockquote>
|
|
<p>Not used.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_11"></a>STDERR</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard error shall be used to write the timing statistics. If <b>-p</b> is specified, the following format shall be used
|
|
in the POSIX locale:</p>
|
|
|
|
<pre>
|
|
<tt>"real %f\nuser %f\nsys %f\n", <</tt><i>real seconds</i><tt>>, <</tt><i>user seconds</i><tt>>,
|
|
<</tt><i>system seconds</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>where each floating-point number shall be expressed in seconds. The precision used may be less than the default six digits of
|
|
<tt>%f</tt> , but shall be sufficiently precise to accommodate the size of the clock tick on the system (for example, if there were
|
|
60 clock ticks per second, at least two digits shall follow the radix character). The number of digits following the radix
|
|
character shall be no less than one, even if this always results in a trailing zero. The implementation may append white space and
|
|
additional information following the format shown here.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_12"></a>OUTPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_13"></a>EXTENDED DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_14"></a>EXIT STATUS</h4>
|
|
|
|
<blockquote>
|
|
<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,
|
|
the <i>time</i> utility shall exit with one of the following values:</p>
|
|
|
|
<dl compact>
|
|
<dt>1-125</dt>
|
|
|
|
<dd>An error occurred in the <i>time</i> utility.</dd>
|
|
|
|
<dt> 126</dt>
|
|
|
|
<dd>The utility specified by <i>utility</i> was found but could not be invoked.</dd>
|
|
|
|
<dt> 127</dt>
|
|
|
|
<dd>The utility specified by <i>utility</i> could not be found.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_15"></a>CONSEQUENCES OF ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_04_141_16"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <a href="../utilities/command.html"><i>command</i></a>, <a href="../utilities/env.html"><i>env</i></a>, <a href=
|
|
"../utilities/nice.html"><i>nice</i></a>, <a href="../utilities/nohup.html"><i>nohup</i></a>, <i>time</i>, and <a href=
|
|
"../utilities/xargs.html"><i>xargs</i></a> utilities have been specified to use exit code 127 if an error occurs so that
|
|
applications can distinguish "failure to find a utility" from "invoked utility exited with an error indication". The value 127
|
|
was chosen because it is not commonly used for other meanings; most utilities use small values for "normal error conditions" and
|
|
the values above 128 can be confused with termination due to receipt of a signal. The value 126 was chosen in a similar manner to
|
|
indicate that the utility could be found, but not invoked. Some scripts produce meaningful error messages differentiating the 126
|
|
and 127 cases. The distinction between exit 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 uses 126 when any attempt to <i>exec</i> the utility fails for any other
|
|
reason.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_17"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>It is frequently desirable to apply <i>time</i> to pipelines or lists of commands. This can be done by placing pipelines and
|
|
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
|
|
file.</p>
|
|
|
|
<p>Alternatively, the following command can be used to apply <i>time</i> to a complex command:</p>
|
|
|
|
<pre>
|
|
<tt>time sh -c '</tt><i>complex-command-line</i><tt>'
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_18"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>When the <i>time</i> utility was originally proposed to be included in the ISO POSIX-2:1993 standard, questions were raised
|
|
about its suitability for inclusion on the grounds that it was not useful for conforming applications, specifically:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The underlying CPU definitions from the System Interfaces volume of IEEE Std 1003.1-2001 are vague, so the numeric
|
|
output could not be compared accurately between systems or even between invocations.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The creation of portable benchmark programs was outside the scope this volume of IEEE Std 1003.1-2001.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>However, <i>time</i> does fit in the scope of user portability. Human judgement can be applied to the analysis of the output,
|
|
and it could be very useful in hands-on debugging of applications or in providing subjective measures of system performance. Hence
|
|
it has been included in this volume of IEEE Std 1003.1-2001.</p>
|
|
|
|
<p>The default output format has been left unspecified because historical implementations differ greatly in their style of
|
|
depicting this numeric output. The <b>-p</b> option was invented to provide scripts with a common means of obtaining this
|
|
information.</p>
|
|
|
|
<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
|
|
command. The POSIX definition has been worded to allow this implementation. Consideration was given to invalidating this approach
|
|
because of the historical model from the C shell and System V shell. However, since the System V <i>time</i> utility historically
|
|
has not produced accurate results in pipeline timing (because the constituent processes are not all owned by the same parent
|
|
process, as allowed by POSIX), it did not seem worthwhile to break historical KornShell usage.</p>
|
|
|
|
<p>The term <i>utility</i> is used, rather than <i>command</i>, to highlight the fact that shell compound commands, pipelines,
|
|
special built-ins, and so on, cannot be used directly. However, <i>utility</i> includes user application programs and shell
|
|
scripts, not just the standard utilities.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_19"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_20"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="xcu_chap02.html#tag_02"><i>Shell Command Language</i></a> , <a href="sh.html"><i>sh</i></a> , the System Interfaces
|
|
volume of IEEE Std 1003.1-2001, <a href="../functions/times.html"><i>times</i>()</a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_21"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 2.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_141_22"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>This utility is marked as part of the User Portability Utilities option.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|