Questions tagged [gettimeofday]

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

Read more in the Linux Reference.

100 questions
0
votes
1 answer

Understanding the output of gettimeofday

I am trying to understand the precision of the gettimeofday() system call. Here's my program: #include #include #include #include #include int main(int argc, char *argv[]) { struct timeval…
Sahil Gupta
  • 103
  • 9
0
votes
0 answers

system() API getting stuck occasionally

I have a code where I am running the system API to check the pid of another process in a while(1) loop. There is a sleep of 1 sec in the loop. Also I am checking if the call is getting executed every second or not in this…
Sekhar
  • 1
0
votes
1 answer

How to get exactly the same result of timeval with C++11 chrono

In my C++ project, there is a very old function, which used the system function of Linux to do some calculation about time. Here is a picec of code: struct timeval tv; gettimeofday(&tv, NULL); uint32_t seqId = (tv.tv_sec % 86400)*10000 + tv.tv_usec…
Yves
  • 11,597
  • 17
  • 83
  • 180
0
votes
1 answer

why NDK GetCurrentTime incorrect?

I use the following code unsigned long long appUtils::GetCurrentTime() { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec * 1000 + tv.tv_usec / 1000; } This code runs on the OSX platform. After clang is compiled, the output…
k000x
  • 1
  • 2
0
votes
3 answers

Finding time slice for threads using gettimeofday

I'm trying to find the time slice of a program, first I assigned to each of the threads an ID to help identify them in their f function. In the f function, I used the timeval struct to check for the start and finish times, subtract them from each…
SA.93
  • 141
  • 14
0
votes
0 answers

Why is strace not listing gettimeofday() in strace

I saw so many links showing that the strace is listing gettimeofday as a syscall in its output, but in my case I feel like it is getting broken down to other calls. Am i missing anything ? I am running in VM on linux 4.4 kernel and ubuntu…
0
votes
2 answers

How to measure the time in seconds between two characters while user inserting them as an input

How to measure inserting time in seconds? I tried to use: struct timeval t1,t2; I checked time before inserting input: gettimeofday(&t1,NULL); and the same after getting the input: gettimeofday(&t2,NULL); double elapsedTime=(t2.tv_sec -…
0
votes
2 answers

Strange stamp on gettimeofday()

I have written this code for a sampling assignment at my university. #include #include #include #include int main(int argc, char **argv){ struct timeval tv; float t = atoi(argv[1]); //sampling…
Giannis
  • 75
  • 9
0
votes
1 answer

Why would seconds field would be about 30,000 different between a MAC and ESP32 (Arduino) synced to same NTP server?

Does anyone know why the seconds field would be about 30,000 different between a MAC and ESP32 (Arduino) synced to the same NTP server? I have a group of ESP32 chips with NTP clients running, and they all sync from a local Windows10 NTP server, and…
Dave
  • 1,521
  • 17
  • 31
0
votes
3 answers

Control loop time with usleep

I try to make sure the execution time of each loop to 10ms with usleep , but sometimes it exceeds 10ms. I have no idea how to solve this problem, is it proper to use usleep and gettimeofday in this case? Please help my find out what i…
zhiyo
  • 11
  • 3
0
votes
1 answer

Computation time of processor varies on execution, each time by using gettimeofday() in a C program

I am trying to compare the computation time for performance comparison using different C libraries with gettimeofday() by including time.h and sys/time.h header files. I used gettimeofday() at the start and end of my computation and took the…
Ema
  • 79
  • 1
  • 6
0
votes
1 answer

gettimeofday possibly failing to get proper time in C

So I've been attempting to get the runtime for a function in my code using the I'm wondering why my code isn't properly counting the time it takes though, since it is returning 0 seconds for a runtime when it shouldn't. Some possibilities I thought…
Brain Meme
  • 61
  • 6
0
votes
1 answer

gettimeofday and time() jumps on BeagleBone - timesyncd?

I have tasks that need to run at reasonably precise intervals in the range of one second. I use gettimeofday() to establish start_usec. After task execution is done, it calls a timedSleep() function. timedSleep() invokes gettimeofday() to calculate…
pbft
  • 41
  • 5
0
votes
2 answers

Program stops unexpectedly when I use gettimeofday() in an infinite loop

I've written a code to ensure each loop of while(1) loop to take specific amount of time (in this example 10000µS which equals to 0.01 seconds). The problem is this code works pretty well at the start but somehow stops after less than a minute. It's…
venth1a
  • 3
  • 5
0
votes
0 answers

Big-endian serialisation of struct timeval

What would be the best way to serialise the struct timeval type obtained via the gettimeofday(2) call? I would like to stick to some standard, so htobe64(3) and friends will not do. The time_t type could possibly be a 64-bit integer and there is no…
Daniel Lovasko
  • 471
  • 2
  • 10