Perl & C code follow: ---------------------------- #### HelloWorld.pl #!/usr/bin/perl -w # HelloWorld.pl pipe2 - bidirectional communication using socketpair # "the best ones always go both ways" use Socket ; use IO::Handle; # thousands of lines just for autoflush :-( # We say AF_UNIX because although *_LOCAL is the # POSIX 1003.1g form of the constant, many machines # still don't have it. socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!"; CHILD->autoflush(1); PARENT->autoflush(1); if ($pid = fork) { # parent #exit ; close PARENT; do { print CHILD "Parent Pid $$ is sending this\n"; print "Parent Pid $$ just read this: `$line`\n"; } while( chomp($line = ) ) ; close CHILD; waitpid($pid,0); } else { # child die "cannot fork: $!" unless defined $pid; close CHILD; while( chomp($line = )) { print "Child Pid $$ just read this: `$line`\n"; print PARENT "Child Pid $$ is sending this\n"; } close PARENT; exit; } ---------------------------------------------------------- spair.c #include #include #include #include #include #include #include char * strupr( char * string ) ; /* Change string to uppercase */ int main(void) { int sv[2]; /* the pair of socket descriptors */ char buf[1024]; /* for data exchange between processes */ int i ; /* counter */ char *ch = "a" ; char * mydata[] = { "alfa", "bravo", "charlie", "delta", "echo" } ; if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) { perror("socketpair"); exit(1); } if (!fork()) { /* child */ /*execlp ("subsn.pl", "subsn.pl", 0);*/ /* Fire the substitution module */ execlp ("HelloWorld.pl", "HelloWorld.pl", 0); /* Fire the substitution module */ for ( i = 0 ; i < 5 ; i ++ ) { read(sv[1], &buf, sizeof( buf ) ); printf("child: read [%s]\n", buf); /*buf = toupper(buf);*/ /* make it uppercase */ strupr( buf ) ; /* make it uppercase */ write(sv[1], &buf, sizeof(buf)); printf("child: sent [%s]\n", buf); } } else { /* parent */ for ( i = 0 ; i < 5 ; i ++ ) { strcpy( buf, mydata[ i ] ) ; /* copy data to buffer */ write(sv[0], buf, sizeof( buf)); printf("parent: sent [%s]\n", buf ); read(sv[0], &buf, sizeof(buf)); printf("parent: read [%s]\n\n", buf); } wait(NULL); /* wait for child to die */ } return 0; } /* ** strupr : Change string to uppercase */ char * strupr( char * string ) { char * original = string ; while ( * string ) { * string = _toupper( *string ) ; string++ ; } return ( original ) ; }