home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / vms / 19930 < prev    next >
Encoding:
Text File  |  1992-12-27  |  3.6 KB  |  89 lines

  1. Newsgroups: comp.os.vms
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!wupost!emory!swrinde!elroy.jpl.nasa.gov!decwrl!deccrl!news.crl.dec.com!dbased.nuo.dec.com!nntpd.lkg.dec.com!nntpd2.cxo.dec.com!adserv.enet.dec.com!winalski
  3. From: winalski@adserv.enet.dec.com (Paul S. Winalski)
  4. Subject: Re: flushing in VAXC and DECC
  5. Message-ID: <1992Dec27.200611.24473@nntpd2.cxo.dec.com>
  6. Lines: 76
  7. Sender: usenet@nntpd2.cxo.dec.com (USENET News System)
  8. Reply-To: winalski@adserv.enet.dec.com (Paul S. Winalski)
  9. Organization: Digital Equipment Corporation, Nashua NH
  10. References: <1992Dec26.211521.4768@spcvxb.spc.edu> <6813@npri6.npri.com>,<1992Dec27.055031.24162@eco.twg.com> <1hjtr9INN34t@gap.caltech.edu>
  11. Date: Sun, 27 Dec 1992 20:06:11 GMT
  12.  
  13.  
  14. In article <1hjtr9INN34t@gap.caltech.edu>,
  15. carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick) writes:
  16.  
  17. [regarding fsync()]
  18. |>
  19. |>Glad to know that it's documented on AXP machines.  Now, perhaps you'd clarify
  20. |>a point for us:  The AXP documentation doesn't agree with what fsync() acutally
  21. |>does under VMS 5.4-2.  In particular, the AXP documentation would have us
  22. |>believe that:
  23. |>    fsync(fileno(stdout));
  24. |>actually causes the results of, e.g., all printf's to be flushed to disk.
  25. |>Now, under VMS 5.4-2, if you spawn a subprocess (using the command
  26. |>"SPAWN/NOWAIT/OUTPUT=file_name RUN program" that runs the program
  27. |>    #include stdio
  28. |>    main()
  29. |>    {    printf("This is a test.");
  30. |>        fsync(fileno(stdout));
  31. |>        sleep(30);
  32. |>    }
  33. |>guess what?  You don't see "This is a test." in the output until the process
  34. |>dies.  However, if the program had been:
  35. |>    #include stdio
  36. |>    main()
  37. |>    {    printf("This is a test.");
  38. |>        fflush(stdout);
  39. |>        fsync(fileno(stdout));
  40. |>        sleep(30);
  41. |>    }
  42. |>you'd see "This is a test." in the output file right away.
  43. |>
  44. |>So, as someone "posing as a guru," I'd like to know whether the function does
  45. |>as it's documented to do, or whether it does what it does under VMS v5.4-2.
  46.  
  47. The function behaves as documented.  It flushes all of the C RTL's internal
  48. buffers and it also does an RMS SYS$FLUSH to force the data to be written to
  49. disk.
  50.  
  51. You're being caught by the special RMS processing for process-permanent files.
  52. When you do a SPAWN/NOWAIT/OUT=filespec, SYS$OUTPUT (aka stdout) is opened in
  53. supervisor mode by DCL as a process-permanent file.  This is done so that each
  54. program run in the subprocess doesn't create its own version of the output file.
  55. Many user-mode RMS operations on a process-permanent file end up being no-ops.
  56. Among these are SYS$OPEN, SYS$CLOSE, and SYS$FLUSH.  So what happens here is
  57. that the DECC RTL does write its buffers and do a SYS$FLUSH, but RMS ignores
  58. the SYS$FLUSH because stdout is a process-permanent file.
  59.  
  60. Note that your second program above (the one with the fflush()) behaves
  61. identically to the first one--you still don't see "This is a test." until the
  62.  
  63. subprocess terminates.  This is because the fsync()'s SYS$FLUSH is still
  64. being ignored.
  65.  
  66. If you change the first program to read:
  67.  
  68.     #include stdio
  69.     #include signal
  70.         main()
  71.         {
  72.         FILE *x;
  73.         x = fopen ("x.x", "w");
  74.         fprintf(x, "This is a test.");
  75.         fsync(fileno(x));
  76.         sleep(30);
  77.         }
  78.  
  79. and then run it using the command SPAWN/NOWAIT/OUT=Y.Y RUN program
  80. you will find that the fsync() flushes "This is a test." to file X.X as the
  81. fsync() documentation would lead one to believe.  It works in this case because
  82. fopen() has opened X.X as a normal RMS file; it is not a process-permanent file,
  83. and so fsync()'s SYS$FLUSH call is honored.
  84.  
  85. fsync(), incidentally, normally is only available on AXP if you compile your
  86. program /STANDARD=VAXC.
  87.  
  88. --PSW
  89.