Named pipe behavior in Linux


 
Thread Tools Search this Thread
Top Forums Programming Named pipe behavior in Linux
# 1  
Old 01-02-2013
Named pipe behavior in Linux

Hi All !

I try to collect importent events from syslog and in my
syslog conf, there is something like this:

Code:
*.*  |/logs/ipes/SLpipe1

I have a program, which opens this pipe and reads the messages from it.

But how this pipe works ? Where can I probably read something about the details, like: Is the pipe buffered, what happens to the sender, if the pipereader dies, is it possibly to connect again, how is the buffersize configured, etc.

Any help would be really great!

Thanks so far and
best regards,

++mabra

Last edited by joeyg; 01-02-2013 at 09:45 PM.. Reason: Please wrap commands and data in CodeTags
# 2  
Old 01-04-2013
Syslog needs a real file, or the udp packets flowing to it may be discarded.

A named pipe is a sort of clue to the O/S to pair up open-for-write and open-for-read calls and pipe them together, so if one appears and not the other, things stall or error out. If there is a service app in a loop opening the pipe for read, forking a child or thread to read it, process the input and close it, it accomodates all client writers:
Code:
$ while :
 do
  ( ksh -c '
   while read l
    do
     echo "$$: $l"
    done
   '& )<p
 done &
[1]     4097
$ date >p                                                                     
$ 4098: Fri Jan  4 09:02:57 EST 2013
$ date >p
4101: Fri Jan  4 09:03:00 EST 2013
$ echo hi >p
$ 4103: hi
ls -l p
prw-r--r--   1 myid        mygrp            0 Jan  4 09:03 p
$

Note that the outer loop stalls trying to open the pipe until a write open on the pipe occurs. It works either way, but seems to be unidirectional.
Code:
$ while :
do
 ksh -c 'echo $$:`date`' >p
done&
[1]     907
$ cat <p
908:Fri Jan 4 11:11:38 EST 2013
$ cat <p
944:Fri Jan 4 11:11:44 EST 2013
$ cat <p
960:Fri Jan 4 11:11:46 EST 2013
$


Last edited by DGPickett; 01-04-2013 at 12:14 PM..
# 3  
Old 01-06-2013
Hi ! Many thanks for your reply !

I believe, that I understand the basics so far.

I let rsyslog write to a pipe and this works well. As long as my pipe reader, a program written in C# from the Mono framework, is running, there are no problems. From test, I saw, that rsyslog continues sending it's messages to the pipe, after my program dis-connects and then re-connects.

Would be great to configure the buffer though.

Best regards,

++mabra
# 4  
Old 01-07-2013
It's still better practice to log it first, even if you want to filter or compress it later, so event alerts are not lost.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Named pipe hanging?

Ok, I can't seem to figure this out or find anything on the web about this. I'm on Sun Solaris, UNIX. I have the following test script: #!/bin/ksh touch test.file LOG=./tmp.log rm -f ${LOG} PIPE=./tmp.pipe mkfifo ${PIPE} trap "rm -f ${PIPE}" EXIT tee -a ${LOG} < ${PIPE} & ... (17 Replies)
Discussion started by: Ditto
17 Replies

2. Shell Programming and Scripting

Named pipe performance

Hi, I am getting data into a Named pipe. Does Named pipe have any size restriction; I know it does not have any storage and it just passes on the data to the next process. I want to know, if there will be a difference in the Named pipe performance if the data input is more. (I am using DB2... (1 Reply)
Discussion started by: sudvishw
1 Replies

3. Shell Programming and Scripting

Using Named pipe in shell script

Hi, I want to use a Named pipe to get input from a growing file for further processing. When I prototype this scenario using a while loop, the data is not written to the named pipe. This the script I use to get data into the Named pipe: #!/bin/ksh mkfifo pipe while (( n <= 10 )) do echo... (2 Replies)
Discussion started by: sudvishw
2 Replies

4. Shell Programming and Scripting

pipe to file named with date

I would like to pipe (redirect ? - what is the right term?) the output of my script to a file named with the current date. If I run this at a command prompt: date +'%Y%m%d" ...it returns "20110429" OK, that's good... so I try: ./script.sh > "'date +%Y%m%d'.csv" I get a file... (1 Reply)
Discussion started by: landog
1 Replies

5. UNIX for Advanced & Expert Users

will a named pipe always be size 0 on filesystem?

I did cat < myFile >> myPipe I was hoping that if I did ls -l, myPipe would now be holding the contents of myFile, and would be the same size. But it was 0. Also strange was that when I did the command above, cat did not return control back to the shell. Why? thanks (4 Replies)
Discussion started by: JamesByars
4 Replies

6. UNIX for Dummies Questions & Answers

fifo or named pipe working?

Can someone explain to me the working of fifo() system call using simple C programs so that I can implement them in the UNIX environement? (1 Reply)
Discussion started by: lvkchaitanya
1 Replies

7. UNIX for Dummies Questions & Answers

Named PIPE

Gurus, I've a File Transaction Server, which communicates with other servers and performs some processing.It uses many Named PIPE's. By mistake i copied a named PIPE into a text file. I heard that PIPE files shouldn't be copied.Isn't it? Since it's a production box, i'm afraid on... (2 Replies)
Discussion started by: Tamil
2 Replies

8. UNIX for Advanced & Expert Users

named pipe with persistent buffer

Hey folks, i need communicate between 2 processes in a reliable manner. The information delivery has to be guarenteed. I thought about proc 2 sending a signal to proc 1 when information has being written to disc and wirte() has been verified (sync/flush). The IPC method for the data is named... (4 Replies)
Discussion started by: heck
4 Replies

9. Programming

IPC using named pipe

Hi All, I am facing a vague issue while trying to make two process talk to each other using named pipe. read process ========= The process which reads, basically creates FIFO using mkfifo - ret_val = mkfifo(HALF_DUPLEX, 0666) func. It then opens the pipe using open func - fd = open... (2 Replies)
Discussion started by: sharanbr
2 Replies

10. UNIX for Advanced & Expert Users

IPC using named pipe

Hi All, I am facing a vague issue while trying to make two process talk to each other using named pipe. read process ========= The process which reads, basically creates FIFO using mkfifo - ret_val = mkfifo(HALF_DUPLEX, 0666);) func. It then opens the pipe using open func - fd =... (1 Reply)
Discussion started by: sharanbr
1 Replies
Login or Register to Ask a Question