MentOS  0.8.0
The Mentoring Operating System
Classes | Macros | Typedefs | Functions
time.h File Reference

Time-related functions. More...

Go to the source code of this file.

Classes

struct  tm
 Used to get information about the current time. More...
 
struct  timeval
 Rappresents time. More...
 
struct  itimerval
 Rappresents a time interval. More...
 
struct  timespec
 Specify intervals of time with nanosecond precision. More...
 

Macros

#define ITIMER_REAL   0
 This timer counts down in real (i.e., wall clock) time. At each expiration, a SIGALRM signal is generated.
 
#define ITIMER_VIRTUAL   1
 This timer counts down against the user-mode CPU time consumed by the process. At each expiration, a SIGVTALRM signal is generated.
 
#define ITIMER_PROF   2
 This timer counts down against the total (i.e., both user and system) CPU time consumed by the process. At each expiration, a SIGPROF signal is generated.
 

Typedefs

typedef unsigned int time_t
 Used to store time values.
 
typedef struct tm tm_t
 Used to get information about the current time.
 
typedef struct timeval timeval_t
 Rappresents time.
 
typedef struct itimerval itimerval_t
 Rappresents a time interval.
 
typedef struct timespec timespec_t
 Specify intervals of time with nanosecond precision.
 

Functions

time_t time (time_t *t)
 Returns the current time. More...
 
time_t difftime (time_t time1, time_t time2)
 Return the difference between the two time values. More...
 
tm_tlocaltime (const time_t *timep)
 The current time broken down into a tm_t structure. More...
 
size_t strftime (char *s, size_t max, const char *format, const tm_t *tm)
 Formats the time tm according to the format specification format and places the result in the character array s of size max. More...
 
int nanosleep (const struct timespec *req, struct timespec *rem)
 Suspends the execution of the calling thread. More...
 
unsigned int sleep (unsigned int seconds)
 Causes the calling thread to sleep either until the number of real-time seconds specified in seconds have elapsed or until a signal arrives which is not ignored. More...
 
int getitimer (int which, struct itimerval *curr_value)
 Fills the structure pointed to by curr_value with the current setting for the timer specified by which. More...
 
int setitimer (int which, const struct itimerval *new_value, struct itimerval *old_value)
 The system provides each process with three interval timers, each decrementing in a distinct time domain. When any timer expires, a signal is sent to the process, and the timer (potentially) restarts. More...
 

Detailed Description

Time-related functions.

Function Documentation

◆ difftime()

time_t difftime ( time_t  time1,
time_t  time2 
)

Return the difference between the two time values.

Parameters
time1The first time value.
time2The second time value.
Returns
The difference in terms of seconds.

◆ getitimer()

int getitimer ( int  which,
struct itimerval curr_value 
)

Fills the structure pointed to by curr_value with the current setting for the timer specified by which.

Parameters
whichwhich timer.
curr_valuewhere we place the timer value.
Returns
0 on success, -1 on failure and errno is set to indicate the error.

◆ localtime()

tm_t* localtime ( const time_t timep)

The current time broken down into a tm_t structure.

Parameters
timepA pointer to a variable holding the current time.
Returns
The time broken down.

◆ nanosleep()

int nanosleep ( const struct timespec req,
struct timespec rem 
)

Suspends the execution of the calling thread.

Parameters
reqThe amount of time we want to sleep.
remThe remaining time we did not sleep.
Returns
If the call is interrupted by a signal handler, nanosleep() returns -1, sets errno to EINTR, and writes the remaining time into the structure pointed to by rem unless rem is NULL.

The execution is suspended until either at least the time specified in *req has elapsed, or the delivery of a signal that triggers the invocation of a handler in the calling thread or that terminates the process.

◆ setitimer()

int setitimer ( int  which,
const struct itimerval new_value,
struct itimerval old_value 
)

The system provides each process with three interval timers, each decrementing in a distinct time domain. When any timer expires, a signal is sent to the process, and the timer (potentially) restarts.

Parameters
whichwhich timer.
new_valuethe new value for the timer.
old_valueoutput variable where the function places the previous value.
Returns
0 on success, -1 on failure and errno is set to indicate the error.

◆ sleep()

unsigned int sleep ( unsigned int  seconds)

Causes the calling thread to sleep either until the number of real-time seconds specified in seconds have elapsed or until a signal arrives which is not ignored.

Parameters
secondsThe number of seconds we want to sleep.
Returns
Zero if the requested time has elapsed, or the number of seconds left to sleep, if the call was interrupted by a signal handler.

◆ strftime()

size_t strftime ( char *  s,
size_t  max,
const char *  format,
const tm_t tm 
)

Formats the time tm according to the format specification format and places the result in the character array s of size max.

Parameters
sThe destination buffer.
maxThe maximum length of the buffer.
formatThe buffer used to generate the time.
tmThe broken-down time.
Returns
The number of bytes (excluding the terminating null) placed in s.

◆ time()

time_t time ( time_t t)

Returns the current time.

Parameters
tWhere the time should be stored.
Returns
The current time.