{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Week7-pipes - Inter-process Communication Pipes(Haviland Ch...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Inter-process Communication Pipes (Haviland – Ch. 7)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Exchanging data between processes After fork() is called we end up with two independent processes. We cannot use variables to communicate between processes since they each have separate address spaces, and separate memory. One easy way to communicate is to use files. – process A writes to a file and process B reads from it. See usefiles.c example. We need to be pretty careful.
Background image of page 2
3 Buffering un-buffered – output appears immediately stderr is not buffered line buffered – output appears when a full line has been written. stdout is line buffered when going to the screen block buffered – output appears when a buffer is filled or a buffer is flushed (on close or explicit flush). normally output to a file is block buffered stdout is block buffered when redirected to a file.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 File Buffering Buffering can be set after stream is opened –void setbuf(FILE *fp, char *buf); – turn buffering off with buf == NULL – turn on with buf pointing to buffer of length BUFSIZ For greater control: –int setvbuf(FILE *fp, char *buf, int mode, size_t size); – set mode to _IOFBF , _IOLBF , or _IONBF for fully buffered, line buffered, or unbuffered –buf points to user buffer, or NULL for system buffer Flush a buffer: int fflush(FILE *fp);
Background image of page 4
5 File Objects and File Descriptors The stdio library provides FILE objects which handle buffering. Why buffering? Efficiency. FILE objects are built on top of file descriptors. A file descriptor is an index into a per-process table of open file descriptors.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}