On Thu, 28 May 1998, Per-Ola Mard wrote:
> I feel that I need to go back to the lab-bench and reinvestigate since
> you guy's find my question kind of hard to understand. People I have
> talked to also say that is should not be any difference in results from
> the two ways to generate a call back. Maybe I'm just messing up things
> here.
It's easy to produce somewhat surprising results though, with perl, where
it looks as if open/close isn't quite what you expect it to be. If you
open a file (say open(FOO,">foo")) and later you dup(2) that (say
open(BAR,">&FOO")), then you close the handle you opened (say close FOO),
you will notice that it's not until your program exits, or you do an
explicit close of the dup(2)ed handle (say close BAR) that the file is
flushed (verifying this is easy).
I think (just haven't had time to verify that) that the same thing happens
if you say fork() in perl, that the file-handles you have open will be
dup(2)ed or something (it inherits open filedescriptors from the parent by
some mechanism which, I guess, is at a lower level than dup(2)). I can
just imagine that your code does a few fork(2) and exec(2)'s, and that you
should be careful to close any open fd's after fork(2)ing so that the
files can be flushed when you *think* that you close your last reference
to them. I leave this for you to verify ;)
/Per
---
Per Boussard, KI/ERA/T/ED Office: +46 8 404 55 11
UNIX System Administrator Fax: +46 8 757 55 50
Ericsson Radio Systems AB Home: +46 8 570 349 67
S-164 80 STOCKHOLM, SWEDEN Email: [EMAIL PROTECTED]
PS
1) On one host (in directory x) I run
rm b;while :; do sleep 1;date ;cat b 2>/dev/null; done
which sez
Thu May 28 23:09:55 MET DST 1998
Thu May 28 23:09:57 MET DST 1998
Thu May 28 23:09:58 MET DST 1998
Thu May 28 23:09:59 MET DST 1998
Thu May 28 23:10:00 MET DST 1998
Thu May 28 23:10:01 MET DST 1998
Thu May 28 23:10:02 MET DST 1998
Thu May 28 23:10:03 MET DST 1998
Opened F,
Closing F
F closed, closing B now
Thu May 28 23:10:04 MET DST 1998
Opened F,
Closing F
F closed, closing B now
Thu May 28 23:10:05 MET DST 1998
Opened F,
Closing F
F closed, closing B now
2) On another host (in directory x) I run..
perl -e 'open (F,">b");open (B,">&F");print F "Opened F,\n";print
`date`,"Opened\n";sleep 3;close F;print B "Closing F\n";print `date`,"Closed
F\n";sleep 3;print B "F closed, closing B now\n";print `date`,"F closed, closing B
now\n";close B' which gives the output
Thu May 28 23:09:56 MET DST 1998
Opened
Thu May 28 23:10:00 MET DST 1998
Closed F
Thu May 28 23:10:03 MET DST 1998
F closed, closing B now