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

HTH
Peter

Replies are listed 'Best First'.
Re^2: sysseek and syswrite fails
by bloonix (Monk) on Oct 15, 2009 at 21:42 UTC
    Hi Peter,

    >>Double check that you're indeed using unbuffered IO everywhere. I am using sysseek, syswrite, sysread.
    >>If I understand you correctly, you're forking
    >>children to read:

    Yes. Each child write its current status to a file that looks like a table.

    >>use strace -f instead for the _real_, _complete_
    >>trace.

    The above strace output was generated with -f for each child.


    >>consider to explicitly open the files separately in
    >>each child (my bet - issues both for the pointer
    >>AND for the locking).

    Hmmm, okay, that could be the solution. The parent is forking and the children uses all opened handles of the parent.

    I test it! Thanks a lot for the suggestions!

    Cheeers,
    Jonny Update: removed small tags
Re^2: sysseek and syswrite fails
by bloonix (Monk) on Oct 15, 2009 at 23:10 UTC

    Hi Peter, it works!

    I just reopened the file and first lock the file and then seek. The daemon runs since 1 hour and it seems to be solved!

    Cheers and good night.
    Jonny