Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How pipe works in this command

Posted on 1999-07-27
Medium Priority
Last Modified: 2012-06-21
when we give piped commands to the shell
e.g. ps -aef |grep httpd |grep -v grep

What happens internally, Does shell really uses pipes or named pipes (fifo),if yes then how  ??
Question by:amresh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 19

Expert Comment

ID: 2011670
I hope this makes's been a while since I did this...

Firstly, pipes are pipes (Eh!), not fifo's

The command in you example will run the ps command and then (I think) spawn another process using the stdout from ps to stdin of the grep this passes the process listing to grep.

grep then extracts all occurances of httpd and in turn passes this to stdout so when the last grep is spawnd this is used as it's input, the grep -v grep removes your actual command and just returns the httpd process line to stdout.

fifo's are normally used in print q's and such like.

I hope this goes somewhat to answer your question, if you want more detail, please post again and I'll drag out some old notes from 1985 ish if I can find them!

LVL 19

Expert Comment

ID: 2011671
Sorry, forgot to check mail response!!!
LVL 14

Accepted Solution

chris_calabrese earned 40 total points
ID: 2011672
jools has it basically right, but the processes are not spawned serially but simultaneously.

Internally, the shell calls:
  o pipe() to create the pipe channels inside the kernel
  o fork() to create multiple child-processes (one for each command in the pipeline plus the original "parent" shell)
  o close() and dup2() to redo the plumbing of the child-processes so their stdin and stdout's are connected appropriately.
  o execve() (or one of it's cousins) so the child-processes can run the actual commands they're supposed to.
  o wait() so the parent process can wait for the children to exit().
LVL 19

Expert Comment

ID: 2011673
Thanks chris, I did say it'd been a while, glad to know I havn't lost touch *that* much.


Expert Comment

ID: 6821553
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects that and the expert will now receive these points, all verified.

Please click on your Member Profile, select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.
Moderator @ Experts Exchange

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (, discussed installing the Solaris Operating S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question