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

Info iconThis preview shows pages 1–7. 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 DocumentRight 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 DocumentRight 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. • We will also use file descriptors for other communication such as pipes and sockets.
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 File Descriptors Used by low-level I/O – open(), close(), read(), write() declared as an integer – int fd; A useful system call to convert a FILE object to a fd
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 08/02/2011.

Page1 / 34

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

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online