i am populating the timespec structure. The intention is, user will always enter values in seconds (can also be 0.01 secs), so we are converting the seconds to nanoseconds using: lt_leak_start = atoll(getenv("LT_LEAK_START")) * sec_to_nsec;
where variable static long sec_to_nsec = 1000000000;
and then using it as an argument to settime: timer_settime(timerid,0,&its,NULL)
. But on doing it an error occurs: settimer failed: Invalid argument
Please help me.
Thanks in advance.
enter code here
struct timespec {
time_t tv_sec; /* Seconds */
long tv_nsec; /* Nanoseconds */
};
struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Initial expiration */
};
The code i am trying is here:
static long sec_to_nsec = 1000000000;
lt_leak_start = atoll(getenv("LT_LEAK_START")) * sec_to_nsec;
/* Setting timer interval */
its.it_interval.tv_sec=0;
its.it_interval.tv_nsec=1;
/* Setting timer expiration */
its.it_value.tv_sec=0; // First expiry after 1 sec
its.it_value.tv_nsec=lt_leak_start;
timer_create(CLOCK_REALTIME,&sevp,&timerid);
if(timer_settime(timerid,0,&its,NULL)==-1) {
perror("settimer failed");
exit(1);
}