Questions tagged [timeval]

56 questions
0
votes
1 answer

questions related to source code of PHP uniqid()

In PHP source code function uniqid() have following C code: (I removed some types to shorten it) //... struct timeval tv; gettimeofday(&tv, NULL); int sec = (int) tv.tv_sec; int usec = (int) (tv.tv_usec % 0x100000); // The max value usec can have…
Nick
  • 9,962
  • 4
  • 42
  • 80
0
votes
1 answer

Switching between statements if the user inputs something: infinitely and with a timeout

To explain more clearly what I want to do, I want my code to check if the user inputs something (or if another file descriptor than 0 has data to read) every (let's say) 2.5 seconds and so until the program stops. If the user inputs something, a…
TheReader
  • 3
  • 1
0
votes
1 answer

snprintf not printing out a converted timeval using strftime?

I have taken this answer from SO: https://stackoverflow.com/a/2409054/997112 so that I can print timeval structs in a friendly format. I had to change "%s.%06d" for "%s.%06ld" because I was getting compiler warnings: void printTimeval(struct…
user997112
  • 29,025
  • 43
  • 182
  • 361
0
votes
1 answer

select() doesn't use what is set for timeval

I have a snippet below - I've adjusted my tv_usec in several ways, but I keep sitting in a select() loop for almost exactly 10 seconds, regardless of what tv_usec is set at. char buffer[512]; fd_set readfds; struct timeval tv; …
MrDuk
  • 16,578
  • 18
  • 74
  • 133
0
votes
2 answers

are these msec<->timeval functions correct?

I have a bug in this program, and I keep coming back to these two functions, but they look right to me. Anything wrong here? long visual_time_get_msec(VisTime *time_) { visual_log_return_val_if_fail(time_ != NULL, 0); return time_->tv_sec *…
Scott
  • 5,135
  • 12
  • 57
  • 74
0
votes
1 answer

How to write a macro which gets runtime of a function?

Suppose we want to know how long function A runs, we can write code like this struct timeval tpstart,tpend; gettimeofday(&tpstart,NULL); A(); gettimeofday(&tpend,NULL); float timeuse= tpend.tv_sec-tpstart.tv_sec +…
stonestrong
  • 337
  • 1
  • 5
  • 13
0
votes
1 answer

timeval variable declaration in linux

I am using timeval structure in order to get current system time. Normally if I declare it like that: timeval curtime; it is working. However I saw some code where people declare it as: struct timeval curtime; Is there any difference between these…
Avb Avb
  • 545
  • 2
  • 13
  • 25
0
votes
2 answers

Time returned by timeval structure is wrong in Ubuntu

I am trying to see the time taken by select function to moniter files, but when I try to print it, I get a very long number.Here is the code: struct timeval to; to.tv_usec=25; nfds=select(maxfds+1,&readset,NULL,NULL,&to); printf("Time left for…
Alfred
  • 1,543
  • 7
  • 33
  • 45
-1
votes
1 answer

How do I double timeval in C?

I am very new to C and I have the following code where I want to double the timeval, how can I do this? #include struct timeval t ={1, 10000}; while(1){ //some code to use timeval Here I need to double the timeval. Meaning if…
MSH
  • 297
  • 1
  • 3
  • 12
-1
votes
1 answer

I am getting a negative value when I try to convert a uint64_t to struct timeval? //edited

#include #include #include void convert(uint64_t offset ) { struct timeval t; t.tv_sec = offset / 1000000; std::cout << "currentTimeOffset " << offset << "startTimeOffset " << t.tv_sec << std::endl; …
ashok v
  • 408
  • 3
  • 11
-6
votes
1 answer

How to convert from seconds to nanoseconds in a timeval struct?

I want to convert my timeval struct from seconds to nanoseconds, what is the best algorithm to achieve this?
ka123444
  • 15
  • 1
  • 4
1 2 3
4