Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: named pipe and "Text file busy"

by sgt (Deacon)
on Nov 25, 2007 at 21:42 UTC ( #652866=note: print w/replies, xml ) Need Help??

in reply to named pipe and "Text file busy"

There is a contract for the use of a named pipe. I will suppose un*xlike and to simplify I will not talk about non-blocking. For pipes the default is blocking.

  • You need a reader and usually the reader is a long-running process.
  • The reader will block on read as soon as it opens. If there is no reader any writer will block.
  • Remember it *is* a pipe so what gets in must get out... If you write more than a certain maximum number of bytes input is likely to be intermixed between the writers. If the reader does not process the input quickly enough then eventually a writer will be blocked and then all the other writers, so you need some flow analysis or special janitor processes.

    So do you have a permanent reader? If you have a read-once reader the behavior you seem to be experiencing is *normal*. Can it be somehow that the pipe is opened by the two threads? Can you check with lsof or similar the processes that maintain a descriptor opened to the named pipe. If you had posted some code we might have been able to help better.

    % steph@ape (/home/stephan) % % cat #!/bin/ksh trap 'exit 0' INT pipe=named_pipe outfile=out [[ -p $pipe ]] || mkfifo $pipe exec 0<$pipe while dd if=$pipe bs=64 count=1 >> $outfile do print .processing sleep 2 done % steph@ape (/home/stephan) % % jobs [1] + Running ./ &
    cheers --stephan
  • Replies are listed 'Best First'.
    Re^2: named pipe and "Text file busy"
    by finpro (Novice) on Nov 26, 2007 at 20:56 UTC
      Thanks I should note that "text file busy" only happens after i open the pipe with my perl script and terminate it. After that, this error occurs irrespective of whether later i've got the script (reader) running together with the writer or a writer by itself.
      I've checked the pipe is open by one thread only and the descriptor is not maintained after i exit the script.
      The code snippet is quite basic:
      my $alertsthr = threads->new(\&al_thread); $SIG{'INT'} = 'CLEANUP'; sub CLEANUP { print "\nClosing pipe\n"; close PIPE; exit(); } sub al_thread { my $myline; while (1) # keep reading from the pipe until we're killed { print "$config->{FIFO} open\n" if $config->{VERBOSE}; open (PIPE, "$config->{FIFO}") or die "Could not open the input +pipe $config->{FIFO}\n"; while($myline = <PIPE>) { print "read $myline\n" if $config->{VERBOSE}; process_message($myline); } print "$config->{FIFO} EOF\n" if $config->{VERBOSE}; } }

        Is there really any guarantee that the SIGINT will be caught by the right thread? you could try forking which would be ok in this respect.

        Then the ETXTBSY (errno 26) is weird. I see the error only with open(2) but not read(2) or write(2). Cannot reproduce it on hp testdrive.

        cheers --stephan

    Log In?

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: note [id://652866]
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (1)
    As of 2023-10-04 23:59 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found