#include<sys/time.h>
int setitimer(int which,const struct itimerval *new_value,struct itimerval *old_value);
ITIMER_REAL
ITIMER_VIRTUAL
ITIMER_PROF
struct itimerval{
struct timeval it_interval;
struct timeval it_value;
};
struct timeval{
time_t tv_sec;
suseconds_t tv_usec;
};
int getitimer(int which ,struct itimerval *curr_value);
#include<unistd.h>
unsigned int alarm(unsigned int seconds);
unsigned int sleep(unsigned int seconds);
#include<time.h>
int nanosleep(const struct timespec *request,struct timespec *remain);
struct timespec{
time_t tv_sec;
long tv_nsec;
};
#include<time.h>
int clock_gettime(clockid_t clockid,struct timespec *tp);
int clock_getres(clockid_t clockid,struct timespec *res);
clockid的值:
CLOCK_REALTIME
CLOCK_WONOTONIC
CLOCK_PROCESS_CPUTIME_ID
CLOCK_THREAD_CPUTIME_ID
int clock_settime(clockid_t clockid,const struct timespec *tp);
int clock_getcpuclockid(pid_t pid,clockid_t *clockid);
int pthread_getcpuclockid(pthread_t thread,clockid_t *clockid);
int clock_nanosleep(clockid_t clockid,int flags,const struct timespec *request,struct timespec *remain);
#include<signal.h>
#include<time.h>
int timer_create(clockid_t clockid,struct sigevent *evp,timer_t *timerid);
union sigval{
int sival_int;
void *sival_ptr;
};
struct sigevent{
int sigev_notify;
int sigev_signo;
union sigval sigev_value;
union{
pid_t _tid;
struct {
void(*_function)(union sigval);
void *_attribute;
}_sigev_thread;
}_sigev_un;
};
sigevent结构中sigev_notify的值:
SIGEV_NONE
SIGEV_SIGNAL
SIGEV_THREAD
SIGEV_THREAD_ID
int timer_settime(timer_t timerid,int flags,const struct itimerspec *value,struct itimerspec *old_value);
struct itimerspec{
struct timespec it_interval;
struct timespec it_value;
};
struct timespec{
time_t tv_sec;
long tv_nsec;
};
int timer_gettime(timer_t timerid,stuct itimerspec *curr_value);
int timer_delete(timer_t timerid);
int timer_getoverrun(timer_t timerid);
int timerfd_create(int clockid,int flags);
int timerfd_settime(int fd,int flags,const struct itimerspec *new_value,struct itimerspec *old_value);
#include<sys/timerfd.h>
int timerfd_gettime(int fd,struct itimerspec *curr_value);