int pid;Quote:> ) int main(int argc, char *argv[])
> ) {
> ) int r[2], w[2];
pid = fork(); not only if the fork failedQuote:> ) char buff[200];
> )
> ) pipe(r);
> ) pipe(w);
> )
if (pid<0) fork failed; but also so you know what process
if (pid>0); to wait for.
I never remember which end is which, so I'll assume you've got it right.Quote:> ) if (fork()) {
> ) /*************************************************************************/
> ) /* Parent */
> ) /*************************************************************************/
close(w[0]); close(r[1]);
Warning: this kind of full-duplex setup with blocking reads and writes canQuote:> ) write( w[PIPE_WRITE], "Hello\n", 6); /* Send some data */ read(
> ) r[PIPE_READ], buff, 6 ); /* Check for echo'ed data */ printf("%.6s",
deadlock your program. Proceed with caution.
/*************************************************************************/Quote:> ) buff); } else {
> ) /*************************************************************************/
> ) /* Child */
> ) /*************************************************************************/
> ) close( r[0]); /* attatch r[0] to stdout */ close( STDOUT_FILENO); dup2(
> ) r[1], STDOUT_FILENO); close( r[1]);
> )
> ) close( w[1]); /* attatch w[1] to stdin */ close( STDIN_FILENO); dup2(
> ) w[0], STDIN_FILENO); close( w[0]);
> )
> )
--Quote:> ) /* Exec awk, to run a program which just echo's back whatever is it
sent */
> ) /*************************************************************************/
> ) execlp("awk", "awk", "{ print $0 }", NULL); }
> )
> ) return 0;
> ) }
They wait apart in waning day, |meow I don't use no smilies.
They rest their *, the rest is silence.| www.geocities.com
Their empty years are ash and clay. | /SoHo/Studios/5079/index.html
I was flamed by Mattison and all I got was this stupid .signature.