named pipe and "Text file busy"

Discussion in 'Perl Misc' started by mikexf@gmail.com, Nov 25, 2007.

  1. Guest

    Hi There,

    I've got a PERL script which runs on linux and spawns a thread which
    opens a FIFO pipe in read only mode. I use a different program to
    write data to FIFO (written in c or simple echo command). Works like a
    charm, however once I exit the script (via CTRL-C) and restart it, the
    pipe becomes unusable for writing (i.e. no program is able to open it
    for writing - they get back en error message: errno 26 "Text file
    busy"). I need to create another FIFO in order for me use the script
    again.
    Internally I catch CTRL-C signal and close the FIFO explicitly.

    What's wrong? Is it because I have 2 threads running i.e. one does
    some other processing and the second one is responsible for the pipe??
    What's the correct and clean way to exit from multithreaded program in
    Perl? Or is it another issue? Any help would be greatly appreciated.

    Thanks, finpro
    , Nov 25, 2007
    #1
    1. Advertising

  2. Ben Morrow Guest

    Quoth :
    >
    > I've got a PERL


    Perl. Spelling is important.

    > script which runs on linux and spawns a thread which
    > opens a FIFO pipe in read only mode. I use a different program to
    > write data to FIFO (written in c or simple echo command). Works like a
    > charm, however once I exit the script (via CTRL-C) and restart it, the
    > pipe becomes unusable for writing (i.e. no program is able to open it
    > for writing - they get back en error message: errno 26 "Text file
    > busy"). I need to create another FIFO in order for me use the script
    > again.


    That's bizarre. Attempting to write to a pipe which isn't open for
    reading should raise SIGPIPE, and if that is caught the write should
    fail with EPIPE. Are you *sure* this is what's happening? What happens
    if you run this Perl program to write to the pipe:

    #!/usr/bin/perl -l

    use strict;
    use warnings;

    use Errno;

    $SIG{PIPE} = sub { warn "got SIGPIPE" };

    open my $P, '>', 'pipe'
    or die "can't open pipe: $!";

    while (1) {
    print $P 'foo'
    or warn "print failed: $!";
    sleep 2;
    }

    __END__

    > Internally I catch CTRL-C signal and close the FIFO explicitly.


    This shouldn't make any difference: the fifo is closed when your program
    exits anyway.

    > What's wrong? Is it because I have 2 threads running i.e. one does
    > some other processing and the second one is responsible for the pipe??


    Again, shouldn't make any difference.

    Ben
    Ben Morrow, Nov 25, 2007
    #2
    1. Advertising

  3. Guest

    > That's bizarre. Attempting to write to apipewhich isn't open for
    > reading should raise SIGPIPE, and if that is caught the write should
    > fail with EPIPE. Are you *sure* this is what's happening? What happens
    > if you run this Perl program to write to thepipe:
    >



    If i just create a new pipe and there's no script (reader) running,
    then the program blocks.
    If i've got the script running later - it will read 'foo' from the
    pipe. However after i kill the script and then
    run this program again (it does not matter whether i start the reader
    this time, the behavior is identical with either my Perl script
    running or stopped) the program can't write and reports an error "Text
    file busy"

    Thanks
    , Nov 28, 2007
    #3
  4. Ben Morrow Guest

    Quoth :
    > > That's bizarre. Attempting to write to apipewhich isn't open for
    > > reading should raise SIGPIPE, and if that is caught the write should
    > > fail with EPIPE. Are you *sure* this is what's happening? What happens
    > > if you run this Perl program to write to thepipe:

    >
    > If i just create a new pipe and there's no script (reader) running,
    > then the program blocks.
    > If i've got the script running later - it will read 'foo' from the
    > pipe. However after i kill the script and then
    > run this program again (it does not matter whether i start the reader
    > this time, the behavior is identical with either my Perl script
    > running or stopped) the program can't write and reports an error "Text
    > file busy"


    This is very odd: the only way you're supposed to be able to get ETXTBSY
    is by trying to write to a file that's currently being executed. Can you
    write a trivial reader program in C and try that instead? If that fails
    then your problem is with your OS or your filesystem, not with Perl. If
    not, can you tell us

    1. which version of Linux you are using

    2. what type of fs the fifo is being created on

    3. an exact recipe to reproduce the problem, preferably in the form
    of a minimal script that creates a fifo, forks and attempts to talk
    to itself.

    Ben
    Ben Morrow, Nov 28, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lee, wonsun
    Replies:
    1
    Views:
    470
    Jack Klein
    Nov 2, 2004
  2. akineko

    named pipe and Linux

    akineko, Apr 7, 2009, in forum: Python
    Replies:
    2
    Views:
    909
    bobicanprogram
    Apr 8, 2009
  3. Cameron Simpson

    Re: named pipe and Linux

    Cameron Simpson, Apr 7, 2009, in forum: Python
    Replies:
    2
    Views:
    1,901
    Thomas Bellman
    Apr 8, 2009
  4. Hal Vaughan
    Replies:
    0
    Views:
    568
    Hal Vaughan
    Sep 12, 2005
  5. Dave Saville

    exec and named pipe questions

    Dave Saville, Sep 7, 2013, in forum: Perl Misc
    Replies:
    11
    Views:
    276
    Rainer Weikusat
    Sep 9, 2013
Loading...

Share This Page