Code Comments
Programming Forum and web based access to our favorite programming groups.List, I want to make a buffer for my application to write log data to. I've created a fifo (`mkfifo /tmp/buf`) Then I made my PERL script that reads from /tmp/buf. Other programs open and write to /tmp/buf but when they close then my program that is reading from /tmp/buf stops. I want the script that reads and buffers (then parses and other such stuff) not to close when the other folks are done writing to the fifo at /tmp/buf. Ideas? Should I just loop and re-open after every close (seems bad). /djb
Post Follow-up to this messageOn Thursday 25 March 2004 10:30 pm, David Busby wrote:
> List,
> I want to make a buffer for my application to write log data to. I've
> created a fifo (`mkfifo /tmp/buf`) Then I made my PERL script that
> reads from /tmp/buf. Other programs open and write to /tmp/buf but when
> they close then my program that is reading from /tmp/buf stops. I want
> the script that reads and buffers (then parses and other such stuff) not
> to close when the other folks are done writing to the fifo at /tmp/buf.
> Ideas? Should I just loop and re-open after every close (seems bad).
>
> /djb
Hi David,
I think that's the normal for pipes. The way I understand it, a pipe is
simply a meeting point for someone openening a file for writing and one
opening a file for reading. If you open first, your open won't complete
until the other proces tries to open soon. Then their write open is directl
y
connected to your read open. This means that when they close, you're closed
too. As you can see from my code below, you have to re-open every time you
enter the loop.
Gary
#!/usr/bin/perl -w
my $VERSION='1.0.0';
# daemon to sit listening to a pipe and actioning print requests.
select(STDERR); $|=1;
select(STDOUT); $|=1;
my $inp;
chdir $ENV{RWDDATA} || die "cannot cd: $!\n";
die "pipe is missing\n" unless ( -p "rwfifo");
while (1) {
print "opening...";
open(FIN,"rwfifo") || die "cannot open pipe: $!";
print "Done\nreading pipe...";
$_=<FIN>;
chomp;
print "Done\n";
last if (/^quit/i);
next if (/loop/i);
print "executing rwlpr $_ loop .....";
print ((system "rwlpr $_ loop") ? "failed: $?\n" : "done\n");
print "reading pipe...";
}
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.