]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/doc/psd/05.sysman/1.4.t
Update clang to release_39 branch r276489, and resolve conflicts.
[FreeBSD/FreeBSD.git] / share / doc / psd / 05.sysman / 1.4.t
1 .\" Copyright (c) 1983, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)1.4.t       8.1 (Berkeley) 6/8/93
29 .\"
30 .sh "Timers
31 .NH 3
32 Real time
33 .PP
34 The system's notion of the current Greenwich time and the current time
35 zone is set and returned by the call by the calls:
36 .DS
37 #include <sys/time.h>
38
39 settimeofday(tvp, tzp);
40 struct timeval *tp;
41 struct timezone *tzp;
42
43 gettimeofday(tp, tzp);
44 result struct timeval *tp;
45 result struct timezone *tzp;
46 .DE
47 where the structures are defined in \fI<sys/time.h>\fP as:
48 .DS
49 ._f
50 struct timeval {
51         long    tv_sec; /* seconds since Jan 1, 1970 */
52         long    tv_usec;        /* and microseconds */
53 };
54
55 struct timezone {
56         int     tz_minuteswest; /* of Greenwich */
57         int     tz_dsttime;     /* type of dst correction to apply */
58 };
59 .DE
60 The precision of the system clock is hardware dependent.
61 Earlier versions of UNIX contained only a 1-second resolution version
62 of this call, which remains as a library routine:
63 .DS
64 time(tvsec)
65 result long *tvsec;
66 .DE
67 returning only the tv_sec field from the \fIgettimeofday\fP call.
68 .NH 3
69 Interval time
70 .PP
71 The system provides each process with three interval timers,
72 defined in \fI<sys/time.h>\fP:
73 .DS
74 ._d
75 #define ITIMER_REAL     0       /* real time intervals */
76 #define ITIMER_VIRTUAL  1       /* virtual time intervals */
77 #define ITIMER_PROF     2       /* user and system virtual time */
78 .DE
79 The ITIMER_REAL timer decrements
80 in real time.  It could be used by a library routine to
81 maintain a wakeup service queue.  A SIGALRM signal is delivered
82 when this timer expires.
83 .PP
84 The ITIMER_VIRTUAL timer decrements in process virtual time.
85 It runs only when the process is executing.  A SIGVTALRM signal
86 is delivered when it expires.
87 .PP
88 The ITIMER_PROF timer decrements both in process virtual time and when
89 the system is running on behalf of the process.
90 It is designed to be used by processes to statistically profile
91 their execution.
92 A SIGPROF signal is delivered when it expires.
93 .PP
94 A timer value is defined by the \fIitimerval\fP structure:
95 .DS
96 ._f
97 struct itimerval {
98         struct  timeval it_interval;    /* timer interval */
99         struct  timeval it_value;       /* current value */
100 };
101 .DE
102 and a timer is set or read by the call:
103 .DS
104 getitimer(which, value);
105 int which; result struct itimerval *value;
106
107 setitimer(which, value, ovalue);
108 int which; struct itimerval *value; result struct itimerval *ovalue;
109 .DE
110 The third argument to \fIsetitimer\fP specifies an optional structure
111 to receive the previous contents of the interval timer.
112 A timer can be disabled by specifying a timer value of 0.
113 .PP
114 The system rounds argument timer intervals to be not less than the
115 resolution of its clock.  This clock resolution can be determined
116 by loading a very small value into a timer and reading the timer back to
117 see what value resulted.
118 .PP
119 The \fIalarm\fP system call of earlier versions of UNIX is provided
120 as a library routine using the ITIMER_REAL timer.  The process
121 profiling facilities of earlier versions of UNIX
122 remain because
123 it is not always possible to guarantee
124 the automatic restart of system calls after 
125 receipt of a signal.
126 The \fIprofil\fP call arranges for the kernel to begin gathering
127 execution statistics for a process:
128 .DS
129 profil(buf, bufsize, offset, scale);
130 result char *buf; int bufsize, offset, scale;
131 .DE
132 This begins sampling of the program counter, with statistics maintained
133 in the user-provided buffer.