<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<META content="MSHTML 5.00.2314.1000" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<DIV>#include <stdio.h><BR>#include <unistd.h><BR>#include
<sys/types.h><BR><BR>int
main(void)<BR>{<BR>
int fd[2],
nbytes;<BR> pid_t
childpid;<BR> char
string[] = "Hello, world!\n";<BR>
char
readbuffer[80];<BR><BR>
pipe(fd);<BR>
<BR> if((childpid = fork()) ==
-1)<BR>
{<BR>
perror("fork");<BR>
exit(1);<BR>
}<BR><BR> if(childpid ==
0)<BR>
{<BR>
/* Child process closes up input side of pipe
*/<BR>
close(fd[0]);<BR><BR>
/* Send "string" through the output side of pipe
*/<BR>
write(fd[1], string,
(strlen(string)+1));<BR>
exit(0);<BR>
}<BR>
else<BR>
{<BR>
/* Parent process closes up output side of pipe
*/<BR>
close(fd[1]);<BR><BR>
/* Read in a string from the pipe
*/<BR>
nbytes = read(fd[0], readbuffer,
sizeof(readbuffer));<BR>
printf("Received string: %s",
readbuffer);<BR>
}<BR>
<BR> return(0);<BR>}</DIV>
<DIV> </DIV>
<DIV>i am just learning pipes & IPC.. see the code above</DIV>
<DIV>if fork is successful, childpid is zero and only the code under if should
execute.</DIV>
<DIV>in the above if-else loop, the code under if and else both seem to
execute. what </DIV>
<DIV>is the flow here ??</DIV>
<DIV> </DIV>
<DIV>Thanks</DIV>
<DIV>Srinath</DIV></BODY></HTML>