octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wait_for_file ?? [who/what/where does fclose()?]


From: Michael D Godfrey
Subject: Re: wait_for_file ?? [who/what/where does fclose()?]
Date: Fri, 10 Sep 2010 11:44:45 -0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Thunderbird/3.1.3

On 09/10/2010 10:31 AM, bpabbott wrote:
I've been googling and reading on this, as well. A point I wasn't aware of was the pclose() waits for the process to end before closing the pipe .. but does not pause the execution on the c program. Do I understand that correctly?

Ben
Ben,

First, I have to say that "understanding" in this stuff is not a simple matter.  None of the file close
mechanisms do what one might think, i.e. actually complete a process that results in a permanent
final state. Some buffers are flushed by some forms of close, but as far as I know none of the
C closes actually flush the kernel buffers.  If everything else works right most of this does not matter.
But, if you did an fclose and then hit the reset button on your computer, your fclosed file would
certainly be corrupted, as would the rest of the filesystem.

Specifically, the question of what has been done at the exact point that the close returns to
the calling program is also not clear and it depends on specific implementations.  This is one
reason that fflush() is sort of controversial.  It is claimed in some of the documentation that fclose
does an fflush, but this is not always true, and in any case fflush before close changes what has
actually happened at the point of return from the fclose.

For Shai's case, by the way, I am quite sure that he should use pclose, not fclose.  I suspect
that he should not also use fflush before the pclose, but I cannot say for sure.

Now, after all that I think that your understanding of pclose is correct.  Remember that things that
happen within the pipe processing can have lots of side-effects that may persist for any amount
of time.  It is really "up to the programmer" to figure out ways to determine if events that were due
to activity in the pipe have actually completed.

Michael


reply via email to

[Prev in Thread] Current Thread [Next in Thread]