Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
2Activity
0 of .
Results for:
No results containing your search query
P. 1
PC Pipes(unix)

PC Pipes(unix)

Ratings:

5.0

(2)
|Views: 705|Likes:
Published by abdullah samdi

More info:

Categories:Types, School Work
Published by: abdullah samdi on Jan 05, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF or read online from Scribd
See more
See less

05/09/2014

 
1
Computer Engineering DepartmentYarmouk University10/27/2008
Interprocess Communication (IPC)Pipes
CE 466System Programming
Pipes
Pipes are the simplestUnix inter-processcommunicationmechanisms.The
pipe()
system call createsa bufferthatthe caller process can access throughfiledescriptors.The data is written to one file descriptor and isread from the other on afirst-in-first-out basis.
 
2
Pipes
#include <unistd.h>intpipe(intP[2]);
system callused to create a pipe
Where p is atwo elementinteger array
P[1]:file descriptor onupstreamend of pipe
P[0]:file descriptor ondownstreamend of pipe
If successful,
pipe
returns 0. If unsuccessful, pipereturns –1and sets errno.
P[1]P[0]
user process
read fdwrite fd
flow of data
pipe
Pipes
 
3
IPC Using Pipes
Pipes are typically used to communicate betweentwo different processes:
Process A (parent)creates a pipeProcess Aforks twice, creating B and C. Eachprocess closes the ends of the pipe it does not need.
Process B
closesdownstreamend
Process C
closesupstreamend
Process A
closesboth ends
Processes B and C execute other programs,using exec, where file descriptors are retained.
Using Pipes
 
pipe()fork()fork() A loop A loopClose the readingend of pipewrite()exit()Close the writingend of piperead()exit()Continueor exit
Writing process
Parent process A 
 
Reading process
 
pipeClose bothends of pipewait()wait()close(…)close(…)

Activity (2)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->