Sponsored Content
Full Discussion: getting time in mili seconds
Top Forums UNIX for Dummies Questions & Answers getting time in mili seconds Post 91879 by Perderabo on Tuesday 6th of December 2005 09:34:40 AM
Old 12-06-2005
Quote:
Originally Posted by Bhups
cum to the rescue sir Smilie ....a beginner conjures ur help Smilie ...???
You can't squeeze blood from a stone. The standard unix date command doesn't do milliseconds. Posix says: "The resolution of the system clock is unspecified.", but they make it clear elsewhere that a resolution of at least one second is required. Posix does demand that the system clock system calls supply an interface that supports microseconds. But you may not write a portable unix program that needs milliseconds. But as a practical matter, all modern systems will have at least millisecond resolution. But you won't find a standard unix utiliity that supports milliseconds. So you need another program to call from your shell script. Either GNU date or that little utility in the linked thread will do. And don't expect it to work well on any real old unix systems. In fact, even on a modern computer, several milliseconds may occur between the time your script obtains the milliseconds and communicates the timestamp to the outside world. Scripts need to fork and exec external programs to do stuff. That is not conducive to millisecond resolution.You may need to write your program in completely in C and/or use realtime extentions.

(Hmmmm: Vino is dividing the output of %N by 1000000 which implies that %N returns nanoseconds. I'll have to look into that. It's not obvious how to get nanoseconds....)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to display time in minutes n seconds...

Hi all, may i know how to display time in minutes and seconds(may be milliseconds and even smaller that ) in shell scripts.... (1 Reply)
Discussion started by: santy
1 Replies

2. UNIX for Advanced & Expert Users

Time Difference in seconds

It is required to calculate time difference in seconds between epoch time (19700101 00:00:00) and any given date time (e.g. 20010214 14:30:30). Is there any command in unix to get it? Thanks in adv. (1 Reply)
Discussion started by: k_bijitesh
1 Replies

3. UNIX for Dummies Questions & Answers

Real time of a clock for every 60 seconds in unix

hi can any one guide me on how to display real time of a clock in unix for every 60 seconds (2 Replies)
Discussion started by: ramnadh_babu
2 Replies

4. Shell Programming and Scripting

File creation time in seconds

Hi All, Cany any one help me in solving this.. Problem statement: I have a requirement to find the time from which there are no files created in a given directory. For this I am assuming that I need to get the file creation time in seconds, then the current time in seconds using `date +%s`.... (7 Replies)
Discussion started by: chary
7 Replies

5. Shell Programming and Scripting

Time difference in seconds

date1=$(date +"%H:%M:%S") date2=$(date +"01:00:54") diff=$date2-$date1 echo $diff How to get the time difference in seconds. (4 Replies)
Discussion started by: sandy1028
4 Replies

6. Shell Programming and Scripting

Get Current Time in Seconds Perl

hi guys, i need to know how to get the current date/time in seconds and i want to be able to do this in a one liner. like say for instance, if want to get what the time is right now, i'll issue a command like this: ## perl -e ' print scalar(localtime(time + 0)), "\n"' Tue Jul 13 17:45:50... (4 Replies)
Discussion started by: SkySmart
4 Replies

7. Shell Programming and Scripting

Elapsed time in seconds in awk

I am trying to get the ellapsed time in seconds in the body of the awk script. I use unix date to get the time. It works in BEGIN {} but not in the body {} of awk. Any ideas? $ cat a BEGIN { "date +%s" | getline x print x } { "date +%s" | getline y print y } $ echo "one line" |... (3 Replies)
Discussion started by: arturas123
3 Replies

8. Shell Programming and Scripting

Get how much time process has been running in seconds

I use this command to get the time elapsed for a process ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time | grep perl It gives in format 19990 0.0 0.0 user /usr/bin/php 5-09:58:51 /usr/bin/php I need in seconds. Please use CODE tags for sample input and output as well... (2 Replies)
Discussion started by: anil510
2 Replies

9. Shell Programming and Scripting

Time in seconds on AIX 4.3.2.0

Hi to everybody again i Need your help, i wasting hours but can't find a solutuin for my Problem. I am not an expert with AIX script programming. I have a csh script and i need the time in seconds but since i have an old AIX the Option -%s doesnot exist with the date command. I seach in Google... (13 Replies)
Discussion started by: Nadielosabra
13 Replies

10. Shell Programming and Scripting

Converting seconds to time

I have a list of time spans in seconds, and want to compute the time span as hh:mm:nn I am coding in bash and have coded the following. However, the results are wrong as "%.0f" rounds the values. Example: ftm: 25793.5 tmspan(hrs,min,sec): 7.16 429.89 25793.50 hh: 7 mm: 10 ss:... (2 Replies)
Discussion started by: kristinu
2 Replies
CLOCK_GETTIME(3)					   BSD Library Functions Manual 					  CLOCK_GETTIME(3)

NAME
clock_gettime, clock_settime, clock_getres, clock_gettime_nsec_np -- get/set date and time SYNOPSIS
#include <time.h> int clock_gettime(clockid_t clock_id, struct timespec *tp); int clock_settime(clockid_t clock_id, const struct timespec *tp); int clock_getres(clockid_t clock_id, struct timespec *tp); uint64_t clock_gettime_nsec_np(clockid_t clock_id); DESCRIPTION
The clock_gettime() and clock_settime() functions allow the calling process to retrieve or set the value used by a clock which is specified by clock_id. clock_id can be a value from one of 5 predefined values: CLOCK_REALTIME the system's real time (i.e. wall time) clock, expressed as the amount of time since the Epoch. This is the same as the value returned by gettimeofday(2). CLOCK_MONOTONIC clock that increments monotonically, tracking the time since an arbitrary point, and will continue to increment while the system is asleep. CLOCK_MONOTONIC_RAW clock that increments monotonically, tracking the time since an arbitrary point like CLOCK_MONOTONIC. However, this clock is unaffected by frequency or time adjustments. It should not be compared to other system time sources. CLOCK_MONOTONIC_RAW_APPROX like CLOCK_MONOTONIC_RAW, but reads a value cached by the system at context switch. This can be read faster, but at a loss of accuracy as it may return values that are milliseconds old. CLOCK_UPTIME_RAW clock that increments monotonically, in the same manner as CLOCK_MONOTONIC_RAW, but that does not increment while the sys- tem is asleep. The returned value is identical to the result of mach_absolute_time() after the appropriate mach_timebase conversion is applied. CLOCK_UPTIME_RAW_APPROX like CLOCK_UPTIME_RAW, but reads a value cached by the system at context switch. This can be read faster, but at a loss of accuracy as it may return values that are milliseconds old. CLOCK_PROCESS_CPUTIME_ID clock that tracks the amount of CPU (in user- or kernel-mode) used by the calling process. CLOCK_THREAD_CPUTIME_ID clock that tracks the amount of CPU (in user- or kernel-mode) used by the calling thread. The structure pointed to by tp is defined in <sys/time.h> as: struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ }; Only the CLOCK_REALTIME clock can be set, and only the superuser may do so. The resolution of a clock is returned by the clock_getres() call. This value is placed in a (non-null) *tp. This value may be smaller than the actual precision of the underlying clock, but represents a lower bound on the resolution. As a non-portable extension, the clock_gettime_nsec_np() function will return the clock value in 64-bit nanoseconds. RETURN VALUES
A 0 return value indicates that the call succeeded. A -1 return value indicates an error occurred, and in this case an error code is stored into the global variable errno. For clock_gettime_nsec_np() a return value of non-0 indicates success. A 0 return value indicates an error occurred and an error code is stored in errno. ERRORS
clock_gettime(), clock_settime(), clock_getres(), and clock_gettime_nsec_np() will fail if: [EINVAL] clock_id is not a valid value. [EFAULT] The tp argument address referenced invalid memory. In addition, clock_settime() may return the following errors: [EPERM] A user other than the superuser attempted to set the time. [EINVAL] clock_id specifies a clock that isn't settable, tp specifies a nanosecond value less than zero or greater than 1000 mil- lion, or a value outside the range of the specified clock. SEE ALSO
date(1), getitimer(2), gettimeofday(2), HISTORY
These functions first appeared in Mac OSX 10.12 STANDARDS
The clock_gettime(), clock_settime(), and clock_getres() system calls conform to IEEE Std 1003.1b-1993 (``POSIX.1''). cleck_gettime_nsec_np() is a non-portable Darwin extension. The clock IDs CLOCK_MONOTONIC_RAW and CLOCK_UPTIME_RAW are extensions to the POSIX interface. BSD
January 26, 2016 BSD
All times are GMT -4. The time now is 07:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy