Strange time() vs. stat() bug
chris at eneevax.UUCP
chris at eneevax.UUCP
Sat Dec 3 20:22:48 AEST 1983
I think this is a bug, but maybe someone can claim a "reasonable" reason
for it:
If I write to a tty device and then close it, a stat 10 seconds later
usually does not show it to have been modified when I did the write+close,
but instead, 5 to 10 seconds later! If I use stat() instead of time() I
get the "right" value (which then remains consistent). Using sync() will
also make the value remain consistent (thus "time()" will be OK in the
program below).
I suspect there's something odd going on with the delayed I/O system here.
---------------------------- BUG DEMONSTRATER ----------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
main () {
FILE *fp;
time_t shouldbe;
struct stat was;
char *tty, *ttyname ();
tty = ttyname (0);
fp = fopen (tty, "w");
fprintf (fp, "testing\n");
fclose (fp);
time (&shouldbe);
sleep (10);
stat (tty, &was);
printf ("was %d should be <= %d\n", was.st_mtime, shouldbe);
}
--
Chris Torek, UMCP, CSD
UUCP: {allegra,seismo,brl-bmd}!umcp-cs!chris
ARPA: chris at maryland CSNet: chris at umcp-cs
More information about the Comp.unix.wizards
mailing list