shell - How linux Os let applications read from pipe -


i confused how linux let application read pipe "cat /etc/hosts | grep 'localhost'". know in independent program fork child , communicate pipe between each other. 2 independent program communicating pipe don't know how. in example "cat /etc/hosts | grep 'localhost'" how grep know file descriptor should read input "cat /etc/hosts". there "conventional" pipe provided os, let grep know input? want know mechanism behind this.

grep in example gets stdin. shell's responsibility call pipe(2) create pipe , dup2(2) in each of fork(2) children assign end of pipe stdin or stdout before calling 1 of exec(3) functions run other executables.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -