Questions tagged [timespec]

'timespec' is a structure allowing to store the time since Epoch (1. Jan 1970) providing nano seconds along with seconds. It is a POSIX extension to the C Standard to be declared in ''.

36 questions
1
vote
1 answer

Get time stamp from cmsg can be NULL?

I looking at this code https://elixir.bootlin.com/linux/v4.6.7/source/Documentation/networking/timestamping/timestamping.c#L181 This code try to print the timestamp of packet using struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg); If this…
Kokomelom
  • 143
  • 1
  • 10
1
vote
1 answer

Convert localtime in seconds since epoch to UTC

In my system I have a PC (Linux, in case it matters) which keeps RTC time in UTC, making my localtime timezone specific. In PC code, I get UTC time as seconds since epoch using struct timespec tv; clock_gettime(CLOCK_REALTIME, &tv); double time =…
Paul Grinberg
  • 1,184
  • 14
  • 37
1
vote
2 answers

struct timespec used in multiple source files: C

new user so I'm sorry if this explanation isn't clear enough...I am having trouble creating timespec variables to be modified/used between multiple source files. My program is meant to determine the time it takes to execute another program from…
M White
  • 13
  • 3
1
vote
1 answer

Convert from unix timespec to NTP

I need to convert from unix timespec to NTP timestamp: Epoch, seconds from era, fraction of second. NTP Timestamp is explained here: NTP Timestamp Here is my code. Do you think that it is OK? void unix_ns_2ntp(struct ntp_time *ntp, const struct…
1
vote
3 answers

Perl module for parsing natural language time duration specifications (similar to the "at" command)?

I'm writing a perl script that takes a "duration" option, and I'd like to be able to specify this duration in a fairly flexible manner, as opposed to only taking a single unit (e.g. number of seconds). The UNIX at command implements this kind of…
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
1
vote
1 answer

what is the difference between timespec and struct timespec?

I try to create a code for generating of timestamp. I found two different structures, but its not clear what is the difference? Can anybody help me to understand what is the difference between these two structures? struct timespec and timespec now?
check
  • 33
  • 1
  • 5
1
vote
1 answer

Better way to get absolute time?

Currently I'm trying to get absolute time to use with pthread_mutex_timedlock. I know I need to add the timeval from gettimeofday to the timespec and then add my arbitrary amount of time. The below works but it might overflow when multiplying with…
Brandon
  • 22,723
  • 11
  • 93
  • 186
1
vote
1 answer

Non-Blocking TCP Socket hangs when timespec initialized (C++)

I have a tcp server running on my localhost. My program connects to this tcp server, which responds with data on connection. I'm using signals elsewhere in the program, so I need this to be non-blocking. Unfortunately, I also need to use…
ahagen
  • 600
  • 6
  • 13
1
vote
2 answers

Execution time of functions decreases at runtime. (C++) Why?

For some testing purposes I have written a piece of code for measuring execution times of several fast operations in my real-time video processing code. And things are working fine. I am getting very realistic results, but i noticed one interesting…
Erik Kaju
  • 3,147
  • 3
  • 19
  • 28
0
votes
2 answers

In struct timespec tv_sec and tv_nsec express the same time in seconds and in nano-seconds or they have to be sum for obtaining the time?

double timespec_delta2milliseconds(struct timespec *last, struct timespec *previous) { return (last->tv_sec - previous->tv_sec) + (last->tv_nsec - previous->tv_nsec)*pow(10,-3); } This function computes the difference (last - previous) and…
0
votes
0 answers

timespec redefinition error occurs after applying all known solutions

so I'm using visual studio 2019 and I installed pthread package but whenever I run my code the following error pops up "'timespec': 'struct' type redefinition " the most common solution I found is to put #define HAVE_STRUCT_TIMESPEC before including…
zamnas
  • 1
  • 1
0
votes
1 answer

Trying to get time from command line and store it in struct timespec variable

I am trying to input a time in a epoch format from the command line and I want to store it in a struct timespec variable. I am able to store it and somehow print it but when I add something to the timespec variable it is giving strange things This…
rass92
  • 45
  • 1
  • 8
0
votes
3 answers

Viability of using the "tv_nsec" nanosecond component returned by "timespec_get()" on Linux as random number generator in C?

With the following simple code snippet: struct timespec ts; for (int i = 0; i < 100; i++) { timespec_get(&ts, TIME_UTC); printf("%ld, ", ts.tv_nsec % 100); } I get output like this: 58, 1, 74, 49, 5, 59, 89, 20, 52, 86, 17, 48, 79, 10, 41,…
Theo d'Or
  • 783
  • 1
  • 4
  • 17
0
votes
2 answers

Is it possible to run an AccuRev query at an arbitrary time in the past?

I want to keep project metrics for my over time which I can show as a report. For example, I want to show a line chart of how many issues were WIP, Assigned, or Completed at the end of each week. Can I run the query at an arbitrary date in the past…
zekel
  • 9,227
  • 10
  • 65
  • 96
0
votes
0 answers

sem_timedwait causes "The futex facility returned an unexpected error code"

What is wrong with this code? When the sem object is posted, it is fine. However as soon as it needs to wait for the time out, I get "The futex facility returned an unexpected error code". void* BackgroudProc(void*){ struct timespec ts; …
0x64
  • 124
  • 8