The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tee into 2 named pipes zzol UNIX for Advanced & Expert Users 9 12-12-2006 08:10 PM
FIFO named pipes tej.buch Shell Programming and Scripting 1 02-10-2006 12:15 AM
cd using pipes Sinbad Shell Programming and Scripting 2 09-09-2004 11:05 AM
PIPEs and Named PIPEs (FIFO) Buffer size Jus Filesystems, Disks and Memory 1 08-20-2004 11:14 AM
named pipes truma1 Shell Programming and Scripting 4 11-21-2001 12:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-11-2007
kanchan_agr kanchan_agr is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 1
named pipes

How to have a conversation between 2 processes using named pipes?
  #2 (permalink)  
Old 09-11-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
A very simple example... Open a shell and type:


Code:
mknod myfifo p
echo "test" > myfifo

At this point the shell hangs, because the fifo is waiting to be read.
So, open a second shell and type:


Code:
cat myfifo

The command reads (and empties) the pipe, you will see the output "test" and the first shell will return to the prompt.
  #3 (permalink)  
Old 09-12-2007
royalibrahim royalibrahim is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 86
What is the need for "p" after myfifo? what is it meant for?
  #4 (permalink)  
Old 09-12-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Quote:
Originally Posted by royalibrahim View Post
What is the need for "p" after myfifo? what is it meant for?
mknod is the unix command for creating special files. A pipe is a type of special file, and with the "p" option you tell mknod to create a FIFO (aka named pipe).

varungupta has explained the behaviour of normal command piping. In this case, the OS creates a temporary file for doing the work (a pipe), but you cannot reference explicitly this pipe by name, because is managed internally by the OS.
If you specifically need to put in communication two or more processes through NAMED pipes, you have to create a FIFO with mknod as explained before. In this manner you can reference explicitly the file on disk.

Generally, named pipes are used in the cases where a specific command line utility doesn't accept pipes as input, and you are forced to pass a phisical file to the utility as the input data. For these situations, named pipes are the answer.
  #5 (permalink)  
Old 09-12-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Quote:
Originally Posted by kanchan_agr View Post
How to have a conversation between 2 processes using named pipes?
pipes !!

command1 | command2

means the o/p of command1 will be given as an input to command2.
Ex: grep "abc" file1 | wc -l
Means the o/p of grep command will be given to wc -l as input to count the no. of lines where "abc" has found in the file1

Is that you were looking for ?? If not, then explain your Q, once again !!


Thnks. !!
  #6 (permalink)  
Old 09-12-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Quote:
Originally Posted by varungupta View Post
pipes !!

command1 | command2

means the o/p of command1 will be given as an input to command2.
Ex: grep "abc" file1 | wc -l
Means the o/p of grep command will be given to wc -l as input to count the no. of lines where "abc" has found in the file1

Is that you were looking for ?? If not, then explain your Q, once again !!


Thnks. !!
And I must say...every command is treated as a saperate process with uniqueue process id. hence in the above example, there were 2 processes linked using pipe.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0