Questions tagged [gettimeofday]

The function gettimeofday() can get the time as well as a timezone.

Read more in the Linux Reference.

100 questions
2
votes
1 answer

OSX gettimeofday syscall on x86_64 seems to not work

I'm making a call to gettimeofday via the syscall instruction using 64bit code. I can't get any results back and am getting told via Dtrace that the call worked with no errors, but the registers I get back from the call are garbage. I do the…
2
votes
2 answers

C++ gettimeofday() returns the same value

/* * Returns time in s.usec */ float mtime() { struct timeval stime; gettimeofday(&stime,0x0); return (float)stime.tv_sec+((float)stime.tv_usec)/1000000000; } main(){ while(true){ cout<
Stefan Rogin
  • 1,499
  • 3
  • 25
  • 41
2
votes
2 answers

usleep() to calculate elapsed time behaves weird

I am calculating time elapsed in milli seconds for each successive call to handler function using the code below. When i use usleep(1000) i.e. 1 ms time difference between each call is 10 ms and when i use usleep(1000000) i.e. 1 sec surprisingly…
vikas_2kx
  • 37
  • 6
2
votes
1 answer

Week Incrementation using Javascript

I'm working on a reminders application using Phonegap [Javascript + Html5] in which the user enters the weekly task he wants to be reminded of and I'm supposed to alert a notification every week on that day. Now the point is: I use Phonegap Local…
Sana Joseph
  • 1,948
  • 7
  • 37
  • 58
2
votes
1 answer

C++: fmodf() & fmod() - Strange Results?

So, I needed a way to be able to get the second of the day, so I messed around with fmod() & gettimeofday() (Mac OSX). However, I came into some odd results along the way: #include #include #include class A…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
1
vote
1 answer

C: gettimeofday() produces the same value every run

I'm trying to print the time in ISO-8601 with decisecond precision. YYYY-MM-DDThh:mm:ss.s Here is my code: #include #include #include #include #include void milli_time(char* dest, struct…
julianc
  • 177
  • 1
  • 10
1
vote
1 answer

why struct timeval return 0 after first use? and how to over come this problem?

I am making a simple Sender and Reciever to check the time difference between using Reno CC algorithm and a Cubic CC algorithm. in order to make an accurate comparison between them I am using struct timeval instead of clock, and I am also adding a…
Dolev Dublon
  • 643
  • 1
  • 6
  • 16
1
vote
1 answer

Why the 2nd diff is so different from the others, using gettimeofday in a loop?

This function is quite new for me, so I just writed a little program to get familiar with it. Here's a my program (just printing laps between several calls of gettimeofday). #include #include #include #include…
UnDesSix
  • 68
  • 1
  • 1
  • 8
1
vote
0 answers

Which value will gettimeofday () return when the system's RTC has not yet been set to the current time?

It's about an all-fresh system without NTP or any other external time signal source, whose real-time clock hasn't even been set yet manually. When I query it by using int gettimeofday (struct timeval *tv, struct timezone *tz); …which return value…
Neppomuk
  • 1,102
  • 1
  • 11
  • 24
1
vote
1 answer

Gettimeofday not working when assigned to variable

I have a simple timestamp issue. I am trying to get a timestamp using gettimeofday and it all works as it should when I print the value to the terminal however when I assign it to a variable it does not. I can not figure out what im doing wrong. The…
JakobVinkas
  • 1,003
  • 7
  • 23
1
vote
1 answer

Why does a timerfd periodic Linux timer expire a little before than expected?

I am using a Linux periodic timer, in particular, timerfd, which I set to expire periodically, for instance, every 200 ms. I noticed, however, that the timer seems to expire, sometimes, a little before with respect to the timeout I set. In…
es483
  • 361
  • 2
  • 16
1
vote
1 answer

Accurate Timestamps using gettimeofday and localtime

I'm attempting to monitor system time elapsed across multiple applications and data paths via gettimeoday and localtime. In this example, I want to grab the system time (microsecond percision) right before my code runs. I'm currently doing it like…
fbd39j
  • 35
  • 2
  • 4
1
vote
1 answer

date uses gettimeofday?

When I do: date system call on freeBSD, does it internally use gettimeofday ? Another que: how do I know where the code of "date" command sitting on the system? Thanks.
hari
  • 9,439
  • 27
  • 76
  • 110
1
vote
0 answers

Undefined behavior using gettimeofday

#include #include static long elapsedTime(struct timeval &then) { struct timeval when; gettimeofday(&when, NULL); long result = (when.tv_sec - then.tv_sec) * 1000; result += (when.tv_usec - then.tv_usec) /…
heyblackduck
  • 117
  • 13
1
vote
3 answers

logical time versus physical time in ubuntu linux

i am measuring physical time between two events like this: #include #include timeval wall_time0; timeval wall_time1; // start of period measurement gettimeofday( &wall_time0 , 0); ...stuff happening // end of period…
lurscher
  • 25,930
  • 29
  • 122
  • 185