named pipes versus the unnamed pipeline using "|"

named pipes versus the unnamed pipeline using "|"

Post by Ashis » Wed, 01 Jun 2005 17:04:36



Hi,

We have a shell script which does something like this:

    $pipe = /tmp/xxx
    mkfifo $pipe
    log_reader_script < $pipe &

    main_program | tee -a $pipe &

I was wondering, if I do the following:

    main_program | tee -a | log_reader_script

What are the avantages, disadvantages of each approach?

Thanks for your kind help.

Regards,
Ashish

 
 
 

named pipes versus the unnamed pipeline using "|"

Post by Robert Bono » Thu, 02 Jun 2005 05:18:25




>Hi,

>We have a shell script which does something like this:

>    $pipe = /tmp/xxx
>    mkfifo $pipe
>    log_reader_script < $pipe &

>    main_program | tee -a $pipe &

>I was wondering, if I do the following:

>    main_program | tee -a | log_reader_script

>What are the avantages, disadvantages of each approach?

The first approach works.

The second generates a syntax error.

the '-a' option for tee(1) requires a parameter (interpreted as a file name)
to follow it.  There is no such parameter before the '|' that terminates the
current command and begins the next command.

 
 
 

named pipes versus the unnamed pipeline using "|"

Post by Ashis » Thu, 02 Jun 2005 10:23:00


Thanks.
Sorry for sending this without testing it myself.

So, if we do :

    main_program | tee -a /dev/tty | log_reader_script &

Are there any advantages/disadvantages over :

    $pipe = /tmp/xxx
    mkfifo $pipe
    log_reader_script < $pipe &

    main_program | tee -a $pipe &

Another question related to pipes: Can two processes read from the same
named pipe ?
I experimented as follows.
First, I had given the command: log_reader_script < $pipe &
After some time, I gave the command: log_reader_script1 < $pipe &
It seemed to me that after giving the second command, log_reader_script
stopped reading from $pipe and log_reader_script1 started reading from
$pipe.

Is this expected, correct behaviour.

Thanks and regards,
Ashish

 
 
 

named pipes versus the unnamed pipeline using "|"

Post by Robert Bono » Fri, 03 Jun 2005 03:55:16




>Thanks.
>Sorry for sending this without testing it myself.

>So, if we do :

>    main_program | tee -a /dev/tty | log_reader_script &

>Are there any advantages/disadvantages over :

>    $pipe = /tmp/xxx
>    mkfifo $pipe
>    log_reader_script < $pipe &

>    main_program | tee -a $pipe &

Consider what happens if you put either of those inside a script file.

Now consider what happens if you re-direct the output of that script.

Quote:>Another question related to pipes: Can two processes read from the same
>named pipe ?
>I experimented as follows.
>First, I had given the command: log_reader_script < $pipe &
>After some time, I gave the command: log_reader_script1 < $pipe &
>It seemed to me that after giving the second command, log_reader_script
>stopped reading from $pipe and log_reader_script1 started reading from
>$pipe.

>Is this expected, correct behaviour.

*THAT* is a messy question.

What happens if you have two processes trying to read from a device (say a
tty) simultaneously?

Any given input goes to _one_ of the processes.

But "which one"?

GOOD question!

See "nasal pigs" for an authoritative discussion of how these kind of
situations work.

 
 
 

1. "|" named pipes...

I have used the command mknod <file> p to make a named pipe.  Specifically, it
is .plan.  I was running a daemon process to log finger activity upon fingering
The .plan would pipe to the process and log.  Anyway, this didn't seem to work.
I would be glad to hear from anyone who has experience with this subject.  
What I want to do is ...  when .plan is accessed, I want it to pipe to an executable script.

Thankz for the help.

Markus

2. 4.5 ISO Not consitant. I must press the issue.

3. Problem reading from pipe ("|") using read()

4. gcc & libstdc++

5. simple question about using pipe "|"

6. Remote Mount of Tape Drive?

7. Problem reading from pipe ("|") using read() -- Solved

8. Linux Frequently Asked Questions with Answers (Part 2 of 6)

9. "size" indication in "ls" of named pipe

10. I can't get my "|" or "" keys to work!

11. alias: |"filter"|"/usr/lib/sendmail realuser"--Is this safe?

12. GETSERVBYNAME()????????????????????"""""""""""""

13. how to use execvp() to execute Unix commands with "|" piped commands?