|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Finding the elapsed time
Hi,
I would like to find the elapsed time(in hours and minutes) since a certain file was modified by comparing it with the system time. Is there an unix command that can give me this value easily?There is a command called 'tract' which can give this value easily but unfortunately Solaris and HP-UX versions am using do not have this. Please advise me if there is a simple way of doing this. Thanks in Advance, Kaushik |
|
#2
|
|||
|
|||
|
Source code for tract is available here:
http://aips2.nrao.edu/docs/programmer/source.html and elsewhere. - F |
|
#3
|
|||
|
|||
|
Hi,
There is a way to get this via Perl using time and stat functions. The 'time' function gives the Time in seconds since 1970. While the stat function can give the modified time in seconds. The difference will be the elapsed time. Now, do we have a similar function like 'time' in unix ? Has anyone used 'stat' function before in Unix ? Thanks, Kaushik |
|
#4
|
|||
|
|||
|
OK, here is a quick C code example of how to get
what you want. #include <stdio.h> #include <time.h> #include <sys/types.h> #include <sys/stat.h> int main(int argc, char **argv) { struct stat sbuf; time_t t1, t2; if (argc < 2) { fprintf(stderr, "Usage: %s file\n", argv[0]); exit(1); } (void) time(&t1); if (stat(argv[1], &sbuf) < 0) { fprintf(stderr, "ERROR: stat failed\n"); exit(1); } fprintf(stdout, "\nSystem time: %s", ctime(&t1)); fprintf(stdout, "File last modified at: %s", ctime(&sbuf.st_mtime)); fprintf(stdout, "Elapsed time: %ld secs\n", (long) &sbuf.st_mtime - ((long)&t1)); } |
|
#5
|
|||
|
|||
|
Look up man ll there are options (u, l, c) to see the last modified, accessed, etc times.
|
|
#6
|
|||
|
|||
|
[root@servername root]# ./a.out discoverer.key
System time: Tue May 4 10:30:07 2004 File last modified at: Tue Feb 24 13:30:59 2004 Elapsed time: 68 secs Doesn't work that well, I believe - ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Finding the elapsed time |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|