GNU bug report logs -
#6379
process substitution with a give suffix
Previous Next
Reported by: Peng Yu <pengyu.ut <at> gmail.com>
Date: Tue, 8 Jun 2010 18:34:02 UTC
Severity: normal
Done: Jim Meyering <jim <at> meyering.net>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
On 06/08/2010 12:33 PM, Peng Yu wrote:
>> mkfifo myfifo.suffix
>> something >myfifo.suffix &
>> ./program <myfifo.suffix
>> wait
>> rm myfifo.suffix
>
> The above question was sent to bug-bash. But since it is related to
> mkfilo. I redirect it to bug-coreutils.
Your question is about how to use various Unix tools together; rather
than directing to bug-bash or bug-coreutils, you may be better off
directing to a generic shell-programming forum.
As it is, you didn't raise any bug report about the mkfifo program, so
redirecting to coreutils didn't really buy you anything.
>
> I have more than one arguments. I tried the following code. It doesn't
> seem to work for more than one arguments. Would you please let me know
> what is wrong?
>
> BTW, using fifo is going to be much faster than using a temp file as
> it avoid the disk usage, right?
A fifo will have the same speed as a pipe (another name for a fifo is
named pipe; unlike 'foo | bar', where the pipe is anonymous and exists
between exactly two processes, a fifo can be accessed from the file
system by multiple processes, but but under the hood, it uses the same
kernel pipe handling code). It has the drawback of being non-seekable
in comparison to temporary regular files. It has the advantage of
atomic operations not guaranteed by disk files, provided you stick to
transactions below the size guaranteed by your kernel. And if you use a
ramdisk backing store for /tmp, there is little difference in speed
(either way, a ramdisk or a fifo does not have to do disk I/O); but
since you can't guarantee that /tmp is a ramdisk, yes, a fifo can be
faster for interprocess communication. And if used incorrectly, it has
the potential to deadlock your shell script (something that won't happen
with regular files).
>
> $ cat a.txt
> In a.txt
> $ cat b.txt
> In b.txt
> $ cat main.sh
> #!/usr/bin/env bash
>
> mkfifo a.suffix
> cat a.txt >a.suffix &
> mkfifo b.suffix
> cat b.txt >b.suffix &
> cat <a.suffix <b.suffix
This is redirecting stdin twice, with the net effect that cat only sees
the contents of the fifo b.suffix. You probably meant to do:
cat a.suffix b.suffix
> wait
> rm a.suffix b.suffix
> $ ./main.sh
> In b.txt
>
--
Eric Blake eblake <at> redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 14 years and 1 day ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.