in reply to sysseek and syswrite fails
Things you should test:
Concerning inherited filehandles and the file pointer
Note that I use open/print with autoflush instead due to laziness.
1> perl -e 'use IO::Handle; open(FH,">out"); FH->autoflush(1); if(fork){ print FH "aaaa"; sleep 2; print FH "bbb"; close FH }else{ sleep 1; print FH "1111"; seek FH,0,0; print FH "4"; close FH }'
Inherited file handle is shared between parent and child, thus we should find 4bbb1111 in ./out on a reasonably idle host.
2> perl -e 'use IO::Handle; open(FH,">out"); FH->autoflush(1); if(fork){ print FH "aaaa"; sleep 2; print FH "bbb"; close FH }else{ close FH;open(FH,"+<out") or warn "err"; FH->autofl +ush(1); sleep 1; print FH "1111"; seek FH,0,0; print FH "4"; close FH1 }'
Same file but opened separately: 4111bbb - the pointer is no longer shared.
Concerning locking
A single file may not simultaneously have both shared and exclusive locks.
Locks created by flock() are associated with an open file table entry. This
means that duplicate file descriptors (created by, for example, fork(2) or
dup(2)) refer to the same lock, and this lock may be modified or released using
any of these descriptors. Furthermore, the lock is released either by an
explicit LOCK_UN operation on any of these duplicate descriptors, or when all
such descriptors have been closed.
If a process uses open(2) (or similar) to obtain more than one descriptor for
the same file, these descriptors are treated independently by flock(). An
attempt to lock the file using one of these file descriptors may be denied by a
lock that the calling process has already placed via another descriptor.
A process may only hold one type of lock (shared or exclusive) on a file. Sub‐
sequent flock() calls on an already locked file will convert an existing lock to
the new lock mode.
HTH
Peter
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sysseek and syswrite fails
by bloonix (Monk) on Oct 15, 2009 at 21:42 UTC | |
|
Re^2: sysseek and syswrite fails
by bloonix (Monk) on Oct 15, 2009 at 23:10 UTC |