@Go to the ‰ŠP�”›first@�”˜, ‰ŠP�”›previous@�”˜, ‰ŠP�”›next@�”˜, ‰ŠP�”›last@�”˜ section, ‰ŠP�”›table of contents@�”˜.
Œ

ˆ‰SEC294Št�”›Date and Time

@�”˜This chapter describes functions for manipulating dates and times, including functions for determining what the current time is and conversion between different time representations.
The time functions fall into three main categories: þÂ
• Functions for measuring elapsed CPU time are discussed in section ‰ŠP�”›Processor Time@�”˜.
• Functions for measuring absolute clock or calendar time are discussed in section ‰ŠP�”›Calendar Time@�”˜.
• Functions for setting alarms and timers are discussed in section ‰ŠP�”›Setting an Alarm@�”˜.Àð
ˆ‰SEC295Št�”›Processor Time

@�”˜If you're trying to optimize your program or measure its efficiency, it's very useful to be able to know how much Bprocessor time@ or BCPU time@ it has used at any given point. Processor time is different from actual wall clock time because it doesn't include any time spent waiting for I/O or when some other process is running. Processor time is represented by the data type Hclock_t@, and is given as a number of Bclock ticks@ relative to an arbitrary base time marking the beginning of a single program invocation. ‰IDX1431Š‰IDX1432Š‰IDX1433Š‰IDX1434Š‰IDX1435Š
ˆ‰SEC296ŠT�”›Basic CPU Time Inquiry

@�”˜To get the elapsed CPU time used by a process, you can use the Hclock@ function. This facility is declared in the header file H`time.h'@. ‰IDX1436Š
@�”˜In typical usage, you call the Hclock@ function at the beginning and end of the interval you want to time, subtract the values, and then divide by HCLOCKS_PER_SEC@ (the number of clock ticks per second), like this: #include <time.h>

clock_t start, end;
double elapsed;

start = clock();
... /* Do the work. */
end = clock();
elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
Different computers and operating systems vary wildly in how they keep track of processor time. It's common for the internal processor clock to have a resolution somewhere between hundredths and millionths of a second.
In the GNU system, Hclock_t@ is equivalent to Hlong int@ and HCLOCKS_PER_SEC@ is an integer value. But in other systems, both Hclock_t@ and the type of the macro HCLOCKS_PER_SEC@ can be either integer or floating-point types. Casting processor time values to Hdouble@, as in the example above, makes sure that operations such as arithmetic and printing work properly and consistently no matter what the underlying representation is.

AMacro:@ int DCLOCKS_PER_SEC
Â‰IDX1437Š@�”˜The value of this macro is the number of clock ticks per second measured by the Hclock@ function.À

AMacro:@ int DCLK_TCK
Â‰IDX1438Š@�”˜This is an obsolete name for HCLOCKS_PER_SEC@.À

AData Type:@ Dclock_t
Â‰IDX1439Š@�”˜This is the type of the value returned by the Hclock@ function. Values of type Hclock_t@ are in units of clock ticks.À

AFunction:@ clock_t Dclock@ B(void)
Â‰IDX1440Š@�”˜This function returns the elapsed processor time. The base time is arbitrary but doesn't change within a single process. If the processor time is not available or cannot be represented, Hclock@ returns the value H(clock_t)(-1)@.À

ˆ‰SEC297ŠT�”›Detailed Elapsed CPU Time Inquiry

@�”˜The Htimes@ function returns more detailed information about elapsed processor time in a Hstruct tms@ object. You should include the header file H`sys/times.h'@ to use this facility. ‰IDX1441Š

A�”˜Data Type:@ Dstruct tms
Â‰IDX1442Š@�”˜The Htms@ structure is used to return information about process times. It contains at least the following members:
Hclock_t tms_utime
Ä@This is the CPU time used in executing the instructions of the calling process.
ÂHclock_t tms_stime
Ä@This is the CPU time used by the system on behalf of the calling process.
ÂHclock_t tms_cutime
Ä@This is the sum of the Htms_utime@ values and the Htms_cutime@ values of all terminated child processes of the calling process, whose status has been reported to the parent process by Hwait@ or Hwaitpid@; see section ‰ŠP�”›Process Completion@�”˜. In other words, it represents the total CPU time used in executing the instructions of all the terminated child processes of the calling process, excluding child processes which have not yet been reported by Hwait@ or Hwaitpid@.
ÂHclock_t tms_cstime
Ä@This is similar to Htms_cutime@, but represents the total CPU time used by the system on behalf of all the terminated child processes of the calling process.Â

All of the times are given in clock ticks. These are absolute values; in a newly created process, they are all zero. See section ‰ŠP�”›Creating a Process@�”˜.À

AFunction:@ clock_t Dtimes@ B(struct tms *Bbuffer@)
Â‰IDX1443Š@�”˜The Htimes@ function stores the processor time information for the calling process in Bbuffer@.
The return value is the same as the value of Hclock()@: the elapsed real time relative to an arbitrary base. The base is a constant within a particular process, and typically represents the time since system start-up. A value of H(clock_t)(-1)@ is returned to indicate failure.À

DPortability Note:@ The Hclock@ function described in section ‰ŠP�”›Basic CPU Time Inquiry@�”˜, is specified by the ISO C standard. The Htimes@ function is a feature of POSIX.1. In the GNU system, the value returned by the Hclock@ function is equivalent to the sum of the Htms_utime@ and Htms_stime@ fields returned by Htimes@.
ˆ‰SEC298Št�”›Calendar Time

@�”˜This section describes facilities for keeping track of dates and times according to the Gregorian calendar. ‰IDX1444Š‰IDX1445Š‰IDX1446Š
@�”˜There are three representations for date and time information: þÂ
• BCalendar time@ (the Htime_t@ data type) is a compact representation, typically giving the number of seconds elapsed since some implementation-specific base time. ‰IDX1447Š
• @�”˜There is also a Bhigh-resolution time@ representation (the Hstruct timeval@ data type) that includes fractions of a second. Use this time representation instead of ordinary calendar time when you need greater precision. ‰IDX1448Š
• B�”˜Local time@ or Bbroken-down time@ (the Hstruct tm@ data type) represents the date and time as a set of components specifying the year, month, and so on, for a specific time zone. This time representation is usually used in conjunction with formatting date and time values. ‰IDX1449Š‰IDX1450ŠÀð
ˆ‰SEC299ŠT�”›Simple Calendar Time

@�”˜This section describes the Htime_t@ data type for representing calendar time, and the functions which operate on calendar time objects. These facilities are declared in the header file H`time.h'@. ‰IDX1451Š
‰IDX1452Š
A�”˜Data Type:@ Dtime_t
Â‰IDX1453Š@�”˜This is the data type used to represent calendar time. When interpreted as an absolute time value, it represents the number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time. (This date is sometimes referred to as the Bepoch@.) POSIX requires that this count ignore leap seconds, but on some hosts this count includes leap seconds if you set HTZ@ to certain values (see section ‰ŠP�”›Specifying the Time Zone with XTZ@�”˜).
In the GNU C library, Htime_t@ is equivalent to Hlong int@. In other systems, Htime_t@ might be either an integer or floating-point type.À

AFunction:@ double Ddifftime@ B(time_t Btime1@, time_t Btime0@)
Â‰IDX1454Š@�”˜The Hdifftime@ function returns the number of seconds elapsed between time Btime1@ and time Btime0@, as a value of type Hdouble@. The difference ignores leap seconds unless leap second support is enabled.
In the GNU system, you can simply subtract Htime_t@ values. But on other systems, the Htime_t@ data type might use some other encoding where subtraction doesn't work directly.À

AFunction:@ time_t Dtime@ B(time_t *Bresult@)
Â‰IDX1455Š@�”˜The Htime@ function returns the current time as a value of type Htime_t@. If the argument Bresult@ is not a null pointer, the time value is also stored in H*Jresult@. If the calendar time is not available, the value H(time_t)(-1)@ is returned.À

ˆ‰SEC300ŠT�”›High-Resolution Calendar

@�”˜The Htime_t@ data type used to represent calendar times has a resolution of only one second. Some applications need more precision.
So, the GNU C library also contains functions which are capable of representing calendar times to a higher resolution than one second. The functions and the associated data types described in this section are declared in H`sys/time.h'@. ‰IDX1456Š

A�”˜Data Type:@ Dstruct timeval
Â‰IDX1457Š@�”˜The Hstruct timeval@ structure represents a calendar time. It has the following members:
Hlong int tv_sec
Ä@This represents the number of seconds since the epoch. It is equivalent to a normal Htime_t@ value.
ÂHlong int tv_usec
Ä@This is the fractional second value, represented as the number of microseconds. Some times struct timeval values are used for time intervals. Then the Htv_sec@ member is the number of seconds in the interval, and Htv_usec@ is the number of additional microseconds.Â
À

AData Type:@ Dstruct timezone
Â‰IDX1458Š@�”˜The Hstruct timezone@ structure is used to hold minimal information about the local time zone. It has the following members:
Hint tz_minuteswest
Ä@This is the number of minutes west of UTC.
ÂHint tz_dsttime
Ä@If nonzero, daylight saving time applies during some part of the year.Â

The Hstruct timezone@ type is obsolete and should never be used. Instead, use the facilities described in section ‰ŠP�”›Functions and Variables for Time Zones@�”˜.À

It is often necessary to subtract two values of type Hstruct timeval@. Here is the best way to do this. It works even on some peculiar operating systems where the Htv_sec@ member has an unsigned type. /* Subtract the `struct timeval' values X and Y,
storing the result in RESULT.
Return 1 if the difference is negative, otherwise 0. */

int
timeval_subtract (result, x, y)
struct timeval *result, *x, *y;
{
/* Perform the carry for the later subtraction by updating By@. */
if (x->tv_usec < y->tv_usec) {
int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec;
}
if (x->tv_usec - y->tv_usec > 1000000) {
int nsec = (y->tv_usec - x->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec;
y->tv_sec -= nsec;
}

/* Compute the time remaining to wait.
Htv_usec@ is certainly positive. */
result->tv_sec = x->tv_sec - y->tv_sec;
result->tv_usec = x->tv_usec - y->tv_usec;

/* Return 1 if result is negative. */
return x->tv_sec < y->tv_sec;
}

AFunction:@ int Dgettimeofday@ B(struct timeval *Btp@, struct timezone *Btzp@)
Â‰IDX1459Š@�”˜The Hgettimeofday@ function returns the current date and time in the Hstruct timeval@ structure indicated by Btp@. Information about the time zone is returned in the structure pointed at Btzp@. If the Btzp@ argument is a null pointer, time zone information is ignored.
The return value is H0@ on success and H-1@ on failure. The following Herrno@ error condition is defined for this function:
HENOSYS
Ä@The operating system does not support getting time zone information, and Btzp@ is not a null pointer. The GNU operating system does not support using Hstruct timezone@ to represent time zone information; that is an obsolete feature of 4.3 BSD. Instead, use the facilities described in section ‰ŠP�”›Functions and Variables for Time Zones@�”˜.Â
À

AFunction:@ int Dsettimeofday@ B(const struct timeval *Btp@, const struct timezone *Btzp@)
Â‰IDX1460Š@�”˜The Hsettimeofday@ function sets the current date and time according to the arguments. As for Hgettimeofday@, time zone information is ignored if Btzp@ is a null pointer.
You must be a privileged user in order to use Hsettimeofday@.
The return value is H0@ on success and H-1@ on failure. The following Herrno@ error conditions are defined for this function:
HEPERM
Ä@This process cannot set the time because it is not privileged.
ÂHENOSYS
Ä@The operating system does not support setting time zone information, and Btzp@ is not a null pointer.Â
À

AFunction:@ int Dadjtime@ B(const struct timeval *Bdelta@, struct timeval *Bolddelta@)
Â‰IDX1461Š@�”˜This function speeds up or slows down the system clock in order to make gradual adjustments in the current time. This ensures that the time reported by the system clock is always monotonically increasing, which might not happen if you simply set the current time.
The Bdelta@ argument specifies a relative adjustment to be made to the current time. If negative, the system clock is slowed down for a while until it has lost this much time. If positive, the system clock is speeded up for a while.
If the Bolddelta@ argument is not a null pointer, the Hadjtime@ function returns information about any previous time adjustment that has not yet completed.
This function is typically used to synchronize the clocks of computers in a local network. You must be a privileged user to use it. The return value is H0@ on success and H-1@ on failure. The following Herrno@ error condition is defined for this function:
HEPERM
Ä@You do not have privilege to set the time.Â
À

DPortability Note:@ The Hgettimeofday@, Hsettimeofday@, and Hadjtime@ functions are derived from BSD.
ˆ‰SEC301ŠT�”›Broken-down Time

‰IDX1462Š‰IDX1463Š
@�”˜Calendar time is represented as a number of seconds. This is convenient for calculation, but has no resemblance to the way people normally represent dates and times. By contrast, Bbroken-down time@ is a binary representation separated into year, month, day, and so on. Broken down time values are not useful for calculations, but they are useful for printing human readable time.
A broken-down time value is always relative to a choice of local time zone, and it also indicates which time zone was used.
The symbols in this section are declared in the header file H`time.h'@.

AData Type:@ Dstruct tm
Â‰IDX1464Š@�”˜This is the data type used to represent a broken-down time. The structure contains at least the following members, which can appear in any order:
Hint tm_sec
Ä@This is the number of seconds after the minute, normally in the range H0@ through H59@. (The actual upper limit is H60@, to allow for leap seconds if leap second support is available.) ‰IDX1465Š
ÂH�”˜int tm_min
Ä@This is the number of minutes after the hour, in the range H0@ through H59@.
ÂHint tm_hour
Ä@This is the number of hours past midnight, in the range H0@ through H23@.
ÂHint tm_mday
Ä@This is the day of the month, in the range H1@ through H31@.
ÂHint tm_mon
Ä@This is the number of months since January, in the range H0@ through H11@.
ÂHint tm_year
Ä@This is the number of years since H1900@.
ÂHint tm_wday
Ä@This is the number of days since Sunday, in the range H0@ through H6@.
ÂHint tm_yday
Ä@This is the number of days since January 1, in the range H0@ through H365@.
ÂHint tm_isdst
Ä‰IDX1466Š‰IDX1467Š@�”˜This is a flag that indicates whether Daylight Saving Time is (or was, or will be) in effect at the time described. The value is positive if Daylight Saving Time is in effect, zero if it is not, and negative if the information is not available.
ÂHlong int tm_gmtoff
Ä@This field describes the time zone that was used to compute this broken-down time value, including any adjustment for daylight saving; it is the number of seconds that you must add to UTC to get local time. You can also think of this as the number of seconds east of UTC. For example, for U.S. Eastern Standard Time, the value is H-5*60*60@. The Htm_gmtoff@ field is derived from BSD and is a GNU library extension; it is not visible in a strict ISO C environment.
ÂHconst char *tm_zone
Ä@This field is the name for the time zone that was used to compute this broken-down time value. Like Htm_gmtoff@, this field is a BSD and GNU extension, and is not visible in a strict ISO C environment.Â
À

AFunction:@ struct tm * Dlocaltime@ B(const time_t *Btime@)
Â‰IDX1468Š@�”˜The Hlocaltime@ function converts the calendar time pointed to by Btime@ to broken-down time representation, expressed relative to the user's specified time zone.
The return value is a pointer to a static broken-down time structure, which might be overwritten by subsequent calls to Hctime@, Hgmtime@, or Hlocaltime@. (But no other library function overwrites the contents of this object.)
Calling Hlocaltime@ has one other effect: it sets the variable Htzname@ with information about the current time zone. See section ‰ŠP�”›Functions and Variables for Time Zones@�”˜.À

AFunction:@ struct tm * Dgmtime@ B(const time_t *Btime@)
Â‰IDX1469Š@�”˜This function is similar to Hlocaltime@, except that the broken-down time is expressed as Coordinated Universal Time (UTC)---that is, as Greenwich Mean Time (GMT)---rather than relative to the local time zone.
Recall that calendar times are Balways@ expressed in coordinated universal time.À

AFunction:@ time_t Dmktime@ B(struct tm *Bbrokentime@)
Â‰IDX1470Š@�”˜The Hmktime@ function is used to convert a broken-down time structure to a calendar time representation. It also "normalizes" the contents of the broken-down time structure, by filling in the day of week and day of year based on the other date and time components.
The Hmktime@ function ignores the specified contents of the Htm_wday@ and Htm_yday@ members of the broken-down time structure. It uses the values of the other components to compute the calendar time; it's permissible for these components to have unnormalized values outside of their normal ranges. The last thing that Hmktime@ does is adjust the components of the Bbrokentime@ structure (including the Htm_wday@ and Htm_yday@).
If the specified broken-down time cannot be represented as a calendar time, Hmktime@ returns a value of H(time_t)(-1)@ and does not modify the contents of Bbrokentime@.
Calling Hmktime@ also sets the variable Htzname@ with information about the current time zone. See section ‰ŠP�”›Functions and Variables for Time Zones@�”˜.À

ˆ‰SEC302ŠT�”›Formatting Date and Time

@�”˜The functions described in this section format time values as strings. These functions are declared in the header file H`time.h'@. ‰IDX1471Š

A�”˜Function:@ char * Dasctime@ B(const struct tm *Bbrokentime@)
Â‰IDX1472Š@�”˜The Hasctime@ function converts the broken-down time value that Bbrokentime@ points to into a string in a standard format: "Tue May 21 13:46:22 1991\n"
The abbreviations for the days of week are: H`Sun'@, H`Mon'@, H`Tue'@, H`Wed'@, H`Thu'@, H`Fri'@, and H`Sat'@.
The abbreviations for the months are: H`Jan'@, H`Feb'@, H`Mar'@, H`Apr'@, H`May'@, H`Jun'@, H`Jul'@, H`Aug'@, H`Sep'@, H`Oct'@, H`Nov'@, and H`Dec'@.
The return value points to a statically allocated string, which might be overwritten by subsequent calls to Hasctime@ or Hctime@. (But no other library function overwrites the contents of this string.)À

AFunction:@ char * Dctime@ B(const time_t *Btime@)
Â‰IDX1473Š@�”˜The Hctime@ function is similar to Hasctime@, except that the time value is specified as a Htime_t@ calendar time value rather than in broken-down local time format. It is equivalent to asctime (localtime (Btime@))
Hctime@ sets the variable Htzname@, because Hlocaltime@ does so. See section ‰ŠP�”›Functions and Variables for Time Zones@�”˜.À

AFunction:@ size_t Dstrftime@ B(char *Bs@, size_t Bsize@, const char *Btemplate@, const struct tm *Bbrokentime@)
Â‰IDX1474Š@�”˜This function is similar to the Hsprintf@ function (see section ‰ŠP�”›Formatted Input@�”˜), but the conversion specifications that can appear in the format template Btemplate@ are specialized for printing components of the date and time Bbrokentime@ according to the locale currently specified for time conversion (see section ‰ŠP�”›Locales and Internationalization@�”˜).
Ordinary characters appearing in the Btemplate@ are copied to the output string Bs@; this can include multibyte character sequences. Conversion specifiers are introduced by a H`%'@ character, followed by an optional flag which can be one of the following. These flags, which are GNU extensions, affect only the output of numbers:
H_
Ä@The number is padded with spaces.
ÂH-
Ä@The number is not padded at all.
ÂH0
Ä@The number is padded with zeros even if the format specifies padding with spaces.
ÂH^
Ä@The output uses uppercase characters, but only if this is possible (see section ‰ŠP�”›Case Conversion@�”˜).Â

The default action is to pad the number with zeros to keep it a constant width. Numbers that do not have a range indicated below are never padded, since there is no natural width for them.
Following the flag an optional specification of the width is possible. This is specified in decimal notation. If the natural size of the output is of the field has less than the specified number of characters, the result is written right adjusted and space padded to the given size.
An optional modifier can follow the optional flag and width specification. The modifiers, which are POSIX.2 extensions, are:
HE
Ä@Use the locale's alternate representation for date and time. This modifier applies to the H%c@, H%C@, H%x@, H%X@, H%y@ and H%Y@ format specifiers. In a Japanese locale, for example, H%Ex@ might yield a date format based on the Japanese Emperors' reigns.
ÂHO
Ä@Use the locale's alternate numeric symbols for numbers. This modifier applies only to numeric format specifiers.Â

If the format supports the modifier but no alternate representation is available, it is ignored.
The conversion specifier ends with a format specifier taken from the following list. The whole H`%'@ sequence is replaced in the output string as follows:
H%a
Ä@The abbreviated weekday name according to the current locale.
ÂH%A
Ä@The full weekday name according to the current locale.
ÂH%b
Ä@The abbreviated month name according to the current locale.
ÂH%B
Ä@The full month name according to the current locale.
ÂH%c
Ä@The preferred date and time representation for the current locale.
ÂH%C
Ä@The century of the year. This is equivalent to the greatest integer not greater than the year divided by 100. This format is a POSIX.2 extension.
ÂH%d
Ä@The day of the month as a decimal number (range H01@ through H31@).
ÂH%D
Ä@The date using the format H%m/%d/%y@. This format is a POSIX.2 extension.
ÂH%e
Ä@The day of the month like with H%d@, but padded with blank (range H1@ through H31@). This format is a POSIX.2 extension.
ÂH%g
Ä@The year corresponding to the ISO week number, but without the century (range H00@ through H99@). This has the same format and value as H%y@, except that if the ISO week number (see H%V@) belongs to the previous or next year, that year is used instead. This format is a GNU extension.
ÂH%G
Ä@The year corresponding to the ISO week number. This has the same format and value as H%Y@, except that if the ISO week number (see H%V@) belongs to the previous or next year, that year is used instead. This format is a GNU extension.
ÂH%h
Ä@The abbreviated month name according to the current locale. The action is the same as for H%b@. This format is a POSIX.2 extension.
ÂH%H
Ä@The hour as a decimal number, using a 24-hour clock (range H00@ through H23@).
ÂH%I
Ä@The hour as a decimal number, using a 12-hour clock (range H01@ through H12@).
ÂH%j
Ä@The day of the year as a decimal number (range H001@ through H366@).
ÂH%k
Ä@The hour as a decimal number, using a 24-hour clock like H%H@, but padded with blank (range H0@ through H23@). This format is a GNU extension.
ÂH%l
Ä@The hour as a decimal number, using a 12-hour clock like H%I@, but padded with blank (range H1@ through H12@). This format is a GNU extension.
ÂH%m
Ä@The month as a decimal number (range H01@ through H12@).
ÂH%M
Ä@The minute as a decimal number (range H00@ through H59@).
ÂH%n
Ä@A single H`\n'@ (newline) character. This format is a POSIX.2 extension.
ÂH%p
Ä@Either H`AM'@ or H`PM'@, according to the given time value; or the corresponding strings for the current locale. Noon is treated as H`PM'@ and midnight as H`AM'@.
ÂH%P
Ä@Either H`am'@ or H`pm'@, according to the given time value; or the corresponding strings for the current locale, printed in lowercase characters. Noon is treated as H`pm'@ and midnight as H`am'@. This format is a GNU extension.
ÂH%r
Ä@The complete time using the AM/PM format of the current locale. This format is a POSIX.2 extension.
ÂH%R
Ä@The hour and minute in decimal numbers using the format H%H:%M@. This format is a GNU extension.
ÂH%s
Ä@The number of seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC. Leap seconds are not counted unless leap second support is available. This format is a GNU extension.
ÂH%S
Ä@The second as a decimal number (range H00@ through H60@).
ÂH%t
Ä@A single H`\t'@ (tabulator) character. This format is a POSIX.2 extension.
ÂH%T
Ä@The time using decimal numbers using the format H%H:%M:%S@. This format is a POSIX.2 extension.
ÂH%u
Ä@The day of the week as a decimal number (range H1@ through H7@), Monday being H1@. This format is a POSIX.2 extension.
ÂH%U
Ä@The week number of the current year as a decimal number (range H00@ through H53@), starting with the first Sunday as the first day of the first week. Days preceding the first Sunday in the year are considered to be in week H00@.
ÂH%V
Ä@The ISO 8601:1988 week number as a decimal number (range H01@ through H53@). ISO weeks start with Monday and end with Sunday. Week H01@ of a year is the first week which has the majority of its days in that year; this is equivalent to the week containing the year's first Thursday, and it is also equivalent to the week containing January 4. Week H01@ of a year can contain days from the previous year. The week before week H01@ of a year is the last week (H52@ or H53@) of the previous year even if it contains days from the new year. This format is a POSIX.2 extension.
ÂH%w
Ä@The day of the week as a decimal number (range H0@ through H6@), Sunday being H0@.
ÂH%W
Ä@The week number of the current year as a decimal number (range H00@ through H53@), starting with the first Monday as the first day of the first week. All days preceding the first Monday in the year are considered to be in week H00@.
ÂH%x
Ä@The preferred date representation for the current locale, but without the time.
ÂH%X
Ä@The preferred time representation for the current locale, but with no date.
ÂH%y
Ä@The year without a century as a decimal number (range H00@ through H99@). This is equivalent to the year modulo 100.
ÂH%Y
Ä@The year as a decimal number, using the Gregorian calendar. Years before the year H1@ are numbered H0@, H-1@, and so on.
ÂH%z
Ä@RFC 822/ISO 8601:1988 style numeric time zone (e.g., H-0600@ or H+0100@), or nothing if no time zone is determinable. This format is a GNU extension.
ÂH%Z
Ä@The time zone abbreviation (empty if the time zone can't be determined).
ÂH%%
Ä@A literal H`%'@ character.Â

The Bsize@ parameter can be used to specify the maximum number of characters to be stored in the array Bs@, including the terminating null character. If the formatted time requires more than Bsize@ characters, the excess characters are discarded. The return value from Hstrftime@ is the number of characters placed in the array Bs@, not including the terminating null character. If the value equals Bsize@, it means that the array Bs@ was too small; you should repeat the call, providing a bigger array.
If Bs@ is a null pointer, Hstrftime@ does not actually write anything, but instead returns the number of characters it would have written.
According to POSIX.1 every call to Hstrftime@ implies a call to Htzset@. So the contents of the environment variable HTZ@ is examined before any output is produced.
For an example of Hstrftime@, see section ‰ŠP�”›Time Functions Example@�”˜.À

ˆ‰SEC303ŠT�”›Specifying the Time Zone with \TZ

@�”˜In POSIX systems, a user can specify the time zone by means of the HTZ@ environment variable. For information about how to set environment variables, see section ‰ŠP�”›Environment Variables@�”˜. The functions for accessing the time zone are declared in H`time.h'@. ‰IDX1475Š‰IDX1476Š
@�”˜You should not normally need to set HTZ@. If the system is configured properly, the default time zone will be correct. You might set HTZ@ if you are using a computer over the network from a different time zone, and would like times reported to you in the time zone that local for you, rather than what is local for the computer.
In POSIX.1 systems the value of the HTZ@ variable can be of one of three formats. With the GNU C library, the most common format is the last one, which can specify a selection from a large database of time zone information for many regions of the world. The first two formats are used to describe the time zone information directly, which is both more cumbersome and less precise. But the POSIX.1 standard only specifies the details of the first two formats, so it is good to be familiar with them in case you come across a POSIX.1 system that doesn't support a time zone information database.
The first format is used when there is no Daylight Saving Time (or summer time) in the local time zone: Bstd@ Boffset@
The Bstd@ string specifies the name of the time zone. It must be three or more characters long and must not contain a leading colon or embedded digits, commas, or plus or minus signs. There is no space character separating the time zone name from the Boffset@, so these restrictions are necessary to parse the specification correctly.
The Boffset@ specifies the time value one must add to the local time to get a Coordinated Universal Time value. It has syntax like [H+@|H-@]Bhh@[H:Bmm@[H:Bss@]]. This is positive if the local time zone is west of the Prime Meridian and negative if it is east. The hour must be between H0@ and H23@, and the minute and seconds between H0@ and H59@.
For example, here is how we would specify Eastern Standard Time, but without any daylight saving time alternative: EST+5
The second format is used when there is Daylight Saving Time: Bstd@ Boffset@ Bdst@ [Boffset@]H,Bstart@[H/Btime@]H,Bend@[H/Btime@]
The initial Bstd@ and Boffset@ specify the standard time zone, as described above. The Bdst@ string and Boffset@ specify the name and offset for the corresponding daylight saving time time zone; if the Boffset@ is omitted, it defaults to one hour ahead of standard time.
The remainder of the specification describes when daylight saving time is in effect. The Bstart@ field is when daylight saving time goes into effect and the Bend@ field is when the change is made back to standard time. The following formats are recognized for these fields:
HJJn
Â@This specifies the Julian day, with Bn@ between H1@ and H365@. February 29 is never counted, even in leap years.
ÀJn
Â@This specifies the Julian day, with Bn@ between H0@ and H365@. February 29 is counted in leap years.
ÀHMJmH.JwH.Jd
Â@This specifies day Bd@ of week Bw@ of month Bm@. The day Bd@ must be between H0@ (Sunday) and H6@. The week Bw@ must be between H1@ and H5@; week H1@ is the first week in which day Bd@ occurs, and week H5@ specifies the Blast@ Bd@ day in the month. The month Bm@ should be between H1@ and H12@.À

The Btime@ fields specify when, in the local time currently in effect, the change to the other time occurs. If omitted, the default is H02:00:00@.
For example, here is how one would specify the Eastern time zone in the United States, including the appropriate daylight saving time and its dates of applicability. The normal offset from UTC is 5 hours; since this is west of the prime meridian, the sign is positive. Summer time begins on the first Sunday in April at 2:00am, and ends on the last Sunday in October at 2:00am. EST+5EDT,M4.1.0/2,M10.5.0/2
The schedule of daylight saving time in any particular jurisdiction has changed over the years. To be strictly correct, the conversion of dates and times in the past should be based on the schedule that was in effect then. However, this format has no facilities to let you specify how the schedule has changed from year to year. The most you can do is specify one particular schedule--usually the present day schedule--and this is used to convert any date, no matter when. For precise time zone specifications, it is best to use the time zone information database (see below).
The third format looks like this: :Bcharacters@
Each operating system interprets this format differently; in the GNU C library, Bcharacters@ is the name of a file which describes the time zone.
‰IDX1477Š‰IDX1478Š@�”˜If the HTZ@ environment variable does not have a value, the operation chooses a time zone by default. In the GNU C library, the default time zone is like the specification H`TZ=:/etc/localtime'@ (or H`TZ=:/usr/local/etc/localtime'@, depending on how GNU C library was configured; see section ‰ŠP�”›How to Install the GNU C Library@�”˜). Other C libraries use their own rule for choosing the default time zone, so there is little we can say about them.
‰IDX1479Š‰IDX1480Š‰IDX1481Š@�”˜If Bcharacters@ begins with a slash, it is an absolute file name; otherwise the library looks for the file H`/share/lib/zoneinfo/JcharactersH'@. The H`zoneinfo'@ directory contains data files describing local time zones in many different parts of the world. The names represent major cities, with subdirectories for geographical areas; for example, H`America/New_York'@, H`Europe/London'@, H`Asia/Hong_Kong'@. These data files are installed by the system administrator, who also sets H`/etc/localtime'@ to point to the data file for the local time zone. The GNU C library comes with a large database of time zone information for most regions of the world, which is maintained by a community of volunteers and put in the public domain.
ˆ‰SEC304ŠT�”›Functions and Variables for Time Zones

A�”˜Variable:@ char * Dtzname@ B[2]
Â‰IDX1482Š@�”˜The array Htzname@ contains two strings, which are the standard names of the pair of time zones (standard and daylight saving) that the user has selected. Htzname[0]@ is the name of the standard time zone (for example, H"EST"@), and Htzname[1]@ is the name for the time zone when daylight saving time is in use (for example, H"EDT"@). These correspond to the Bstd@ and Bdst@ strings (respectively) from the HTZ@ environment variable. If daylight saving time is never used, Htzname[1]@ is the empty string.
The Htzname@ array is initialized from the HTZ@ environment variable whenever Htzset@, Hctime@, Hstrftime@, Hmktime@, or Hlocaltime@ is called. If multiple abbreviations have been used (e.g. H"EWT"@ and H"EDT"@ for U.S. Eastern War Time and Eastern Daylight Time), the array contains the most recent abbreviation.
The Htzname@ array is required for POSIX.1 compatibility, but in GNU programs it is better to use the Htm_zone@ member of the broken-down time structure, since Htm_zone@ reports the correct abbreviation even when it is not the latest one. À

AFunction:@ void Dtzset@ B(void)
Â‰IDX1483Š@�”˜The Htzset@ function initializes the Htzname@ variable from the value of the HTZ@ environment variable. It is not usually necessary for your program to call this function, because it is called automatically when you use the other time conversion functions that depend on the time zone.À

The following variables are defined for compatibility with System V Unix. Like Htzname@, these variables are set by calling Htzset@ or the other time conversion functions.

AVariable:@ long int Dtimezone
Â‰IDX1484Š@�”˜This contains the difference between UTC and the latest local standard time, in seconds west of UTC. For example, in the U.S. Eastern time zone, the value is H5*60*60@. Unlike the Htm_gmtoff@ member of the broken-down time structure, this value is not adjusted for daylight saving, and its sign is reversed. In GNU programs it is better to use Htm_gmtoff@, since it contains the correct offset even when it is not the latest one.À

AVariable:@ int Ddaylight
Â‰IDX1485Š@�”˜This variable has a nonzero value if daylight savings time rules apply. A nonzero value does not necessarily mean that daylight savings time is now in effect; it means only that daylight savings time is sometimes in effect.À

ˆ‰SEC305ŠT�”›Time Functions Example

@�”˜Here is an example program showing the use of some of the local time and calendar time functions. #include <time.h>
#include <stdio.h>

#define SIZE 256

int
main (void)
{
char buffer[SIZE];
time_t curtime;
struct tm *loctime;

/* Get the current time. */
curtime = time (NULL);

/* Convert it to local time representation. */
loctime = localtime (&curtime);

/* Print out the date and time in the standard format. */
fputs (asctime (loctime), stdout);

/* Print it out in a nice format. */
strftime (buffer, SIZE, "Today is %A, %B %d.\n", loctime);
fputs (buffer, stdout);
strftime (buffer, SIZE, "The time is %I:%M %p.\n", loctime);
fputs (buffer, stdout);

return 0;
}
It produces output like this: Wed Jul 31 13:02:36 1991
Today is Wednesday, July 31.
The time is 01:02 PM.
ˆ‰SEC306Št�”›Setting an Alarm

@�”˜The Halarm@ and Hsetitimer@ functions provide a mechanism for a process to interrupt itself at some future time. They do this by setting a timer; when the timer expires, the process receives a signal.
‰IDX1486Š‰IDX1487Š‰IDX1488Š‰IDX1489Š@�”˜Each process has three independent interval timers available: þÂ
• A real-time timer that counts clock time. This timer sends a HSIGALRM@ signal to the process when it expires. ‰IDX1490Š‰IDX1491Š
• @�”˜A virtual timer that counts CPU time used by the process. This timer sends a HSIGVTALRM@ signal to the process when it expires. ‰IDX1492Š‰IDX1493Š
• @�”˜A profiling timer that counts both CPU time used by the process, and CPU time spent in system calls on behalf of the process. This timer sends a HSIGPROF@ signal to the process when it expires. ‰IDX1494Š‰IDX1495Š@�”˜This timer is useful for profiling in interpreters. The interval timer mechanism does not have the fine granularity necessary for profiling native code.Àð
You can only have one timer of each kind set at any given time. If you set a timer that has not yet expired, that timer is simply reset to the new value.
You should establish a handler for the appropriate alarm signal using Hsignal@ or Hsigaction@ before issuing a call to Hsetitimer@ or Halarm@. Otherwise, an unusual chain of events could cause the timer to expire before your program establishes the handler, and in that case it would be terminated, since that is the default action for the alarm signals. See section ‰ŠP�”›Signal Handling@�”˜.
The Hsetitimer@ function is the primary means for setting an alarm. This facility is declared in the header file H`sys/time.h'@. The Halarm@ function, declared in H`unistd.h'@, provides a somewhat simpler interface for setting the real-time timer. ‰IDX1496Š‰IDX1497Š

A�”˜Data Type:@ Dstruct itimerval
Â‰IDX1498Š@�”˜This structure is used to specify when a timer should expire. It contains the following members:
Hstruct timeval it_interval
Ä@This is the interval between successive timer interrupts. If zero, the alarm will only be sent once.
ÂHstruct timeval it_value
Ä@This is the interval to the first timer interrupt. If zero, the alarm is disabled.Â

The Hstruct timeval@ data type is described in section ‰ŠP�”›High-Resolution Calendar@�”˜.À

AFunction:@ int Dsetitimer@ B(int Bwhich@, struct itimerval *Bnew@, struct itimerval *Bold@)
Â‰IDX1499Š@�”˜The Hsetitimer@ function sets the timer specified by Bwhich@ according to Bnew@. The Bwhich@ argument can have a value of HITIMER_REAL@, HITIMER_VIRTUAL@, or HITIMER_PROF@.
If Bold@ is not a null pointer, Hsetitimer@ returns information about any previous unexpired timer of the same kind in the structure it points to.
The return value is H0@ on success and H-1@ on failure. The following Herrno@ error conditions are defined for this function:
HEINVAL
Ä@The timer interval was too large.Â
À

AFunction:@ int Dgetitimer@ B(int Bwhich@, struct itimerval *Bold@)
Â‰IDX1500Š@�”˜The Hgetitimer@ function stores information about the timer specified by Bwhich@ in the structure pointed at by Bold@.
The return value and error conditions are the same as for Hsetitimer@.À

HITIMER_REAL
Â‰IDX1501Š@�”˜This constant can be used as the Bwhich@ argument to the Hsetitimer@ and Hgetitimer@ functions to specify the real-time timer.
ÀHITIMER_VIRTUAL
Â‰IDX1502Š@�”˜This constant can be used as the Bwhich@ argument to the Hsetitimer@ and Hgetitimer@ functions to specify the virtual timer.
ÀHITIMER_PROF
Â‰IDX1503Š@�”˜This constant can be used as the Bwhich@ argument to the Hsetitimer@ and Hgetitimer@ functions to specify the profiling timer.À

AFunction:@ unsigned int Dalarm@ B(unsigned int Bseconds@)
Â‰IDX1504Š@�”˜The Halarm@ function sets the real-time timer to expire in Bseconds@ seconds. If you want to cancel any existing alarm, you can do this by calling Halarm@ with a Bseconds@ argument of zero.
The return value indicates how many seconds remain before the previous alarm would have been sent. If there is no previous alarm, Halarm@ returns zero.À

The Halarm@ function could be defined in terms of Hsetitimer@ like this: unsigned int
alarm (unsigned int seconds)
{
struct itimerval old, new;
new.it_interval.tv_usec = 0;
new.it_interval.tv_sec = 0;
new.it_value.tv_usec = 0;
new.it_value.tv_sec = (long int) seconds;
if (setitimer (ITIMER_REAL, &new, &old) < 0)
return 0;
else
return old.it_value.tv_sec;
}
There is an example showing the use of the Halarm@ function in section ‰ŠP�”›Signal Handlers that Return@�”˜.
If you simply want your process to wait for a given number of seconds, you should use the Hsleep@ function. See section ‰ŠP�”›Sleeping@�”˜.
You shouldn't count on the signal arriving precisely when the timer expires. In a multiprocessing environment there is typically some amount of delay involved.
DPortability Note:@ The Hsetitimer@ and Hgetitimer@ functions are derived from BSD Unix, while the Halarm@ function is specified by the POSIX.1 standard. Hsetitimer@ is more powerful than Halarm@, but Halarm@ is more widely used.
ˆ‰SEC307Št�”›Sleeping

@�”˜The function Hsleep@ gives a simple way to make the program wait for short periods of time. If your program doesn't use signals (except to terminate), then you can expect Hsleep@ to wait reliably for the specified amount of time. Otherwise, Hsleep@ can return sooner if a signal arrives; if you want to wait for a given period regardless of signals, use Hselect@ (see section ‰ŠP�”›Waiting for Input or Output@�”˜) and don't specify any descriptors to wait for.

AFunction:@ unsigned int Dsleep@ B(unsigned int Bseconds@)
Â‰IDX1505Š@�”˜The Hsleep@ function waits for Bseconds@ or until a signal is delivered, whichever happens first.
If Hsleep@ function returns because the requested time has elapsed, it returns a value of zero. If it returns because of delivery of a signal, its return value is the remaining time in the sleep period.
The Hsleep@ function is declared in H`unistd.h'@.À

Resist the temptation to implement a sleep for a fixed amount of time by using the return value of Hsleep@, when nonzero, to call Hsleep@ again. This will work with a certain amount of accuracy as long as signals arrive infrequently. But each signal can cause the eventual wakeup time to be off by an additional second or so. Suppose a few signals happen to arrive in rapid succession by bad luck--there is no limit on how much this could shorten or lengthen the wait.
Instead, compute the time at which the program should stop waiting, and keep trying to wait until that time. This won't be off by more than a second. With just a little more work, you can use Hselect@ and make the waiting period quite accurate. (Of course, heavy system load can cause unavoidable additional delays--unless the machine is dedicated to one application, there is no way you can avoid this.)
On some systems, Hsleep@ can do strange things if your program uses HSIGALRM@ explicitly. Even if HSIGALRM@ signals are being ignored or blocked when Hsleep@ is called, Hsleep@ might return prematurely on delivery of a HSIGALRM@ signal. If you have established a handler for HSIGALRM@ signals and a HSIGALRM@ signal is delivered while the process is sleeping, the action taken might be just to cause Hsleep@ to return instead of invoking your handler. And, if Hsleep@ is interrupted by delivery of a signal whose handler requests an alarm or alters the handling of HSIGALRM@, this handler and Hsleep@ will interfere.
On the GNU system, it is safe to use Hsleep@ and HSIGALRM@ in the same program, because Hsleep@ does not work by means of HSIGALRM@.
ˆ‰SEC308Št�”›Resource Usage

‰IDX1506Š@�”˜The function Hgetrusage@ and the data type Hstruct rusage@ are used for examining the usage figures of a process. They are declared in H`sys/resource.h'@.

AFunction:@ int Dgetrusage@ B(int Bprocesses@, struct rusage *Brusage@)
Â‰IDX1507Š@�”˜This function reports the usage totals for processes specified by Bprocesses@, storing the information in H*Jrusage@.
In most systems, Bprocesses@ has only two valid values:
HRUSAGE_SELF
Ä@Just the current process.
ÂHRUSAGE_CHILDREN
Ä@All child processes (direct and indirect) that have terminated already.Â

In the GNU system, you can also inquire about a particular child process by specifying its process ID.
The return value of Hgetrusage@ is zero for success, and H-1@ for failure.
HEINVAL
Ä@The argument Bprocesses@ is not valid.Â
À

One way of getting usage figures for a particular child process is with the function Hwait4@, which returns totals for a child when it terminates. See section ‰ŠP�”›BSD Process Wait Functions@�”˜.

AData Type:@ Dstruct rusage
Â‰IDX1508Š@�”˜This data type records a collection usage amounts for various sorts of resources. It has the following members, and possibly others:
Hstruct timeval ru_utime
Ä@Time spent executing user instructions.
ÂHstruct timeval ru_stime
Ä@Time spent in operating system code on behalf of Bprocesses@.
ÂHlong int ru_maxrss
Ä@The maximum resident set size used, in kilobytes. That is, the maximum number of kilobytes that Bprocesses@ used in real memory simultaneously.
ÂHlong int ru_ixrss
Ä@An integral value expressed in kilobytes times ticks of execution, which indicates the amount of memory used by text that was shared with other processes.
ÂHlong int ru_idrss
Ä@An integral value expressed the same way, which is the amount of unshared memory used in data.
ÂHlong int ru_isrss
Ä@An integral value expressed the same way, which is the amount of unshared memory used in stack space.
ÂHlong int ru_minflt
Ä@The number of page faults which were serviced without requiring any I/O.
ÂHlong int ru_majflt
Ä@The number of page faults which were serviced by doing I/O.
ÂHlong int ru_nswap
Ä@The number of times Bprocesses@ was swapped entirely out of main memory.
ÂHlong int ru_inblock
Ä@The number of times the file system had to read from the disk on behalf of Bprocesses@.
ÂHlong int ru_oublock
Ä@The number of times the file system had to write to the disk on behalf of Bprocesses@.
ÂHlong int ru_msgsnd
Ä@Number of IPC messages sent.
ÂHlong ru_msgrcv
Ä@Number of IPC messages received.
ÂHlong int ru_nsignals
Ä@Number of signals received.
ÂHlong int ru_nvcsw
Ä@The number of times Bprocesses@ voluntarily invoked a context switch (usually to wait for some service).
ÂHlong int ru_nivcsw
Ä@The number of times an involuntary context switch took place (because the time slice expired, or another process of higher priority became runnable).Â
À

An additional historical function for examining usage figures, Hvtimes@, is supported but not documented here. It is declared in H`sys/vtimes.h'@.
ˆ‰SEC309Št�”›Limiting Resource Usage

‰IDX1509Š‰IDX1510Š‰IDX1511Š
@�”˜You can specify limits for the resource usage of a process. When the process tries to exceed a limit, it may get a signal, or the system call by which it tried to do so may fail, depending on the limit. Each process initially inherits its limit values from its parent, but it can subsequently change them.
‰IDX1512Š@�”˜The symbols in this section are defined in H`sys/resource.h'@.

AFunction:@ int Dgetrlimit@ B(int Bresource@, struct rlimit *Brlp@)
Â‰IDX1513Š@�”˜Read the current value and the maximum value of resource Bresource@ and store them in H*Jrlp@.
The return value is H0@ on success and H-1@ on failure. The only possible Herrno@ error condition is HEFAULT@.À

AFunction:@ int Dsetrlimit@ B(int Bresource@, struct rlimit *Brlp@)
Â‰IDX1514Š@�”˜Store the current value and the maximum value of resource Bresource@ in H*Jrlp@.
The return value is H0@ on success and H-1@ on failure. The following Herrno@ error condition is possible:
HEPERM
Ä@You tried to change the maximum permissible limit value, but you don't have privileges to do so.Â
À

AData Type:@ Dstruct rlimit
Â‰IDX1515Š@�”˜This structure is used with Hgetrlimit@ to receive limit values, and with Hsetrlimit@ to specify limit values. It has two fields:
Hrlim_cur
Ä@The current value of the limit in question. This is also called the "soft limit". ‰IDX1516Š
ÂH�”˜rlim_max
Ä@The maximum permissible value of the limit in question. You cannot set the current value of the limit to a larger number than this maximum. Only the super user can change the maximum permissible value. This is also called the "hard limit". ‰IDX1517ŠÂ

@�”˜In Hgetrlimit@, the structure is an output; it receives the current values. In Hsetrlimit@, it specifies the new values.À

Here is a list of resources that you can specify a limit for. Those that are sizes are measured in bytes.
HRLIMIT_CPU
Â‰IDX1518Š@�”˜The maximum amount of cpu time the process can use. If it runs for longer than this, it gets a signal: HSIGXCPU@. The value is measured in seconds. See section ‰ŠP�”›Operation Error Signals@�”˜.
ÀHRLIMIT_FSIZE
Â‰IDX1519Š@�”˜The maximum size of file the process can create. Trying to write a larger file causes a signal: HSIGXFSZ@. See section ‰ŠP�”›Operation Error Signals@�”˜.
ÀHRLIMIT_DATA
Â‰IDX1520Š@�”˜The maximum size of data memory for the process. If the process tries to allocate data memory beyond this amount, the allocation function fails.
ÀHRLIMIT_STACK
Â‰IDX1521Š@�”˜The maximum stack size for the process. If the process tries to extend its stack past this size, it gets a HSIGSEGV@ signal. See section ‰ŠP�”›Program Error Signals@�”˜.
ÀHRLIMIT_CORE
Â‰IDX1522Š@�”˜The maximum size core file that this process can create. If the process terminates and would dump a core file larger than this maximum size, then no core file is created. So setting this limit to zero prevents core files from ever being created.
ÀHRLIMIT_RSS
Â‰IDX1523Š@�”˜The maximum amount of physical memory that this process should get. This parameter is a guide for the system's scheduler and memory allocator; the system may give the process more memory when there is a surplus.
ÀHRLIMIT_MEMLOCK
Â@The maximum amount of memory that can be locked into physical memory (so it will never be paged out).
ÀHRLIMIT_NPROC
Â@The maximum number of processes that can be created with the same user ID. If you have reached the limit for your user ID, Hfork@ will fail with HEAGAIN@. See section ‰ŠP�”›Creating a Process@�”˜.
ÀHRLIMIT_NOFILE
Â‰IDX1524Š
ÀH�”˜RLIMIT_OFILE
Â‰IDX1525Š@�”˜The maximum number of files that the process can open. If it tries to open more files than this, it gets error code HEMFILE@. See section ‰ŠP�”›Error Codes@�”˜. Not all systems support this limit; GNU does, and 4.4 BSD does.
ÀHRLIM_NLIMITS
Â‰IDX1526Š@�”˜The number of different resource limits. Any valid Bresource@ operand must be less than HRLIM_NLIMITS@.À

AConstant:@ Dint@ BRLIM_INFINITY
Â‰IDX1527Š@�”˜This constant stands for a value of "infinity" when supplied as the limit value in Hsetrlimit@.À

Two historical functions for setting resource limits, Hulimit@ and Hvlimit@, are not documented here. The latter is declared in H`sys/vlimit.h'@ and comes from BSD.
ˆ‰SEC310Št�”›Process Priority

‰IDX1528Š‰IDX1529Š
‰IDX1530Š@�”˜When several processes try to run, their respective priorities determine what share of the CPU each process gets. This section describes how you can read and set the priority of a process. All these functions and macros are declared in H`sys/resource.h'@.
The range of valid priority values depends on the operating system, but typically it runs from H-20@ to H20@. A lower priority value means the process runs more often. These constants describe the range of priority values:
HPRIO_MIN
Â‰IDX1531Š@�”˜The smallest valid priority value.
ÀHPRIO_MAX
Â‰IDX1532Š@�”˜The smallest valid priority value.À

AFunction:@ int Dgetpriority@ B(int Bclass@, int Bid@)
Â‰IDX1533Š@�”˜Read the priority of a class of processes; Bclass@ and Bid@ specify which ones (see below). If the processes specified do not all have the same priority, this returns the smallest value that any of them has.
The return value is the priority value on success, and H-1@ on failure. The following Herrno@ error condition are possible for this function:
HESRCH
Ä@The combination of Bclass@ and Bid@ does not match any existing process.
ÂHEINVAL
Ä@The value of Bclass@ is not valid.Â

When the return value is H-1@, it could indicate failure, or it could be the priority value. The only way to make certain is to set Herrno = 0@ before calling Hgetpriority@, then use Herrno != 0@ afterward as the criterion for failure.À

AFunction:@ int Dsetpriority@ B(int Bclass@, int Bid@, int Bpriority@)
Â‰IDX1534Š@�”˜Set the priority of a class of processes to Bpriority@; Bclass@ and Bid@ specify which ones (see below).
The return value is H0@ on success and H-1@ on failure. The following Herrno@ error condition are defined for this function:
HESRCH
Ä@The combination of Bclass@ and Bid@ does not match any existing process.
ÂHEINVAL
Ä@The value of Bclass@ is not valid.
ÂHEPERM
Ä@You tried to set the priority of some other user's process, and you don't have privileges for that.
ÂHEACCES
Ä@You tried to lower the priority of a process, and you don't have privileges for that.Â
À

The arguments Bclass@ and Bid@ together specify a set of processes you are interested in. These are the possible values for Bclass@:
HPRIO_PROCESS
Â‰IDX1535Š@�”˜Read or set the priority of one process. The argument Bid@ is a process ID.
ÀHPRIO_PGRP
Â‰IDX1536Š@�”˜Read or set the priority of one process group. The argument Bid@ is a process group ID.
ÀHPRIO_USER
Â‰IDX1537Š@�”˜Read or set the priority of one user's processes. The argument Bid@ is a user ID.À

If the argument Bid@ is 0, it stands for the current process, current process group, or the current user, according to Bclass@.

AFunction:@ int Dnice@ B(int Bincrement@)
Â‰IDX1538Š@�”˜Increment the priority of the current process by Bincrement@. The return value is the same as for Hsetpriority@.
Here is an equivalent definition for Hnice@: int
nice (int increment)
{
int old = getpriority (PRIO_PROCESS, 0);
return setpriority (PRIO_PROCESS, 0, old + increment);
} À

Œ
Go to the ‰ŠP�”›first@�”˜, ‰ŠP�”›previous@�”˜, ‰ŠP�”›next@�”˜, ‰ŠP�”›last@�”˜ section, ‰ŠP�”›table of contents@�”˜.