| To: | yyyyyyyyyyyyyyy@xxxxxxxxxxxxx |
|---|---|
| Subject: | Bug in TC2-d2 pipe() |
| From: | yyyyyyyyy@xxxxxxx |
| Date: | Fri, 18 Jul 2003 14:27:57 +0100 (BST) |
Bug report from : Michael Kerrisk , self
(Note that the reply-to line automatically redirects
to yyyyyyyyyyyyyy@xxxxxxxxxxxxx for further discussion on bug reports)
@ page 1 line 27866 section pipe() comment {pipe example}
Problem:
This is an EXAMPLE for the waitpid() man page. Line number
references are to TC1.
Action:
Change
"None"
to the following:
[[
The following example demonstrates the use of a pipe to
transfer data between a parent process and a child process.
Error handling is excluded, but otherwise this code
demonstrates good practice when using pipes: after the fork()
the two processes close the unused ends of the pipe before
they commence transferring data.
int fildes[2];
const int BSIZE = 100;
char buf[BSIZE];
ssize_t nbytes;
pipe(fildes);
switch (fork()) {
case -1: /* Handle error */
break;
case 0: /* Child - reads from pipe */
close(fildes[1]); /* Write end is unused */
nbytes = read(fildes[0], buf, BSIZE); /* Get data from pipe */
/* At this point, a further read would see end of file... */
close(fildes[0]); /* Finished with pipe */
exit(EXIT_SUCCESS);
default: /* Parent - writes to pipe */
close(fildes[0]); /* Read end is unused */
write(fildes[1], "Hello world\n", 12); /* Write data on pipe */
close(fildes[1]); /* Child will see EOF */
exit(EXIT_SUCCESS);
}
]]
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Defect in XSH exp (revised II), Loic Domaigne |
|---|---|
| Next by Date: | Bug in TC2-d2 popen(), mtk-lists |
| Previous by Thread: | Defect in XSH erf, loic-dev |
| Next by Thread: | Bug in TC2-d2 popen(), mtk-lists |
| Indexes: | [Date] [Thread] [All Lists] |