Re: COBOL Time of Day in micro-seconds or nano-seconds



Robert wrote:

GNU C gettimeofday()

.... is an implementation of the standard gettimeofday(), which is part of the Single UNIX Specification v3, aka the Open Group Base Specifications Issue 6, which is the unified specification that now defines the POSIX base (IEEE 1003.1) and ISO/IEC 9945-1, as well as SUS and OGBS.[1]

(Specifically, it's part of the X/Open Systems Interface Extension, which includes various APIs that are not part of the ISO C library.)

> is available on the most platforms.

And more importantly, gettimeofday is also included in other SUSv3 implementations. It's not defined by or restricted to GNU.

> It returns microsecond
resolution, depending on OS capability of course.

This is an important caveat. Many implementations of gettimeofday are limited by an OS clock granularity much coarser than a microsecond. (In the mid-1990s, for example, 100 Hz - ie, 10 millisecond - resolution was used by several Unix implementations. I don't know offhand what's typical these days.) For better resolution, you generally have to go to platform-specific functions.

> You can call it directly from Cobol.

Here's an example using Micro Focus Server Express to get milliseconds since the beginning of the epoch (midnight 1/1/1970), on 32-bit Solaris:

-----
$set sourceformat(free)

identification division.
program-id. time-in-ms.

data division.
working-storage section.

01 timeval-32bit.
02 seconds pic x(4) comp-5.
02 microseconds pic x(4) comp-5.
77 tzp usage pointer value null.
77 ms-since-epoch pic 9(18) display.

procedure division.
call "gettimeofday" using
by reference timeval-32bit
by value tzp
end-call
compute ms-since-epoch = seconds * 1000 + microseconds / 1000
display ms-since-epoch
stop run
.
-----


[1] http://www.opengroup.org/onlinepubs/009695399/functions/gettimeofday.html

--
Michael Wojcik
Micro Focus
Rhetoric & Writing, Michigan State University
.



Relevant Pages

  • Re: [RFC][PATCH] new timeofday core subsystem (v. A3)
    ... > Hmm. ... > gettimeofday and regular do_gettimeofday be a similar as possible to ... > implementations. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: ZFS group ownership
    ... complying with the Open Group Base Specifications;-) ... effective group ID of the process Implementations shall provide ... file be set to the group ID of its parent directory or to the effective ...
    (freebsd-hackers)