You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
570 B
Perl

use Socket;
use IO::Handle;
socketpair(CHILDHANDLE, PARENTHANDLE, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
or die "Could not create socketpair.";
CHILDHANDLE->autoflush(1);
PARENTHANDLE->autoflush(1);
if ($pid = fork) {
close PARENTHANDLE;
print CHILDHANDLE "the parent!\n";
$line = <CHILDHANDLE>;
print "Parent: $line";
close CHILDHANDLE;
waitpid($pid,0);
} else {
close CHILDHANDLE;
$line = <PARENTHANDLE>;
print "Child : $line";
print PARENTHANDLE "from the child!\n";
close PARENTHANDLE;
exit;
}