In article <42************ *************** *******@q39g200 0hsf.googlegrou ps.com>,
AK <an***********@ gmail.comwrote:
>Please check out this query that I have in :
[a google group, not a usenet group]
>(its a bit long, thats why I am not typing it again; please do check
that link)
>and please do respond... I know there are quite a number of members of
progav in here... This is one query I need resolved asap...
fork() is off topic for comp.lang.c as it is an operating system
routine, not part of the C language.
[OT]
POSIX.1 1989 says,
The fork() function creates a new process. The new process
(child process) shall be an exact copy of the calling process
(parent process) except for the following:
(3) The child process has its own copy of the parent's file
descriptors. Each of the child's file descriptors refer to the
same open file description with the corresponding file
descriptor of the parent.
And -none- of the other differences enumerated have to do with I/O
(except for directory streams.)
Notice that bit about *exact* copy. And notice that file descriptions
are shared. From these two facts we can conclude that there is
an exact copy in each process of whatever was in the file buffers
before the fork() took place.
Your program prints from the file buffers in both processes, so
anything that was in the file buffers is going to be printed in both
processes.
If you need to have something in the file buffer output before
a fork(), you should be using fflush() before the fork().
[/OT]
Your program also ends its output with a printf string that does
not end in a '\n'. C leaves it as implementation defined as to
whether the last line of output will actually be output if the
last line does not end in '\n'. Your program might output the
last line on some systems but not output it on other systems.
--
This is a Usenet signature block. Please do not quote it when replying
to one of my postings.
http://en.wikipedia.org/wiki/Signature_block