This does not answer the current question but answers the original one. So, it is being kept as it has been useful to some people so far.
In shell you could just use the date utility:
date +%s.%N
date +%s%N
nanoseconds_since_70=$(date +%s%N)
From man date:
%s seconds since 1970-01-01 00:00:00 UTC
%N nanoseconds (000000000..999999999)
The nanoseconds portion complement the seconds in the right way: when %N goes from 999999999 to 0 the %s increments one second. I dont have a reference for that (please edit if you can found it) but just works.
date utility x clock_gettime
Note that the number is not affected by changes in time zone but will be affected by changes in the system clock, like the changes made by the system administrator, NTP and adjtime function. However the CLOCK_MONOTONIC in the clock_gettime function is also affected, except by the administrator changes.
CLOCK_MONOTONIC -- Clock that cannot be set and represents monotonic time
since some unspecified starting point. This clock is not affected by
discontinuous jumps in the system time (e.g., if the system administrator
manually changes the clock), but is affected by the incremental adjustments
performed by adjtime(3) and NTP.
Newer system has a better solution: CLOCK_MONOTIC_RAW. Despite that, this is a shell solution as requested.
To know more
Monotonic function in Wikipedia
The @caf user answer from Difference between CLOCK_REALTIME and CLOCK_MONOTONIC?:
CLOCK_MONOTONIC represents the absolute elapsed wall-clock time since some
arbitrary, fixed point in the past. It isn't affected by changes in the
system time-of-day clock.
If you want to compute the elapsed time between two events observed on the one
machine without an intervening reboot, CLOCK_MONOTONIC is the best option.