#!/usr/bin/perl -w

use POSIX;
use Socket;
use IO::Handle;

socketpair(child1, parent1, PF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!";
child1->autoflush(1);
parent1->autoflush(1);

if ($pid = fork) { # parent process
	
	close parent1;

	$in2 = <child1>;
	print $in2;
	
	waitpid($pid, 0); # wait until the child has exited
	close child1;

} else { # child process
	
	die "cannot fork: $!" unless defined $pid;
	close child1;

	setsid;
	setpgrp;

	select STDOUT; $| = 1;
	select STDERR; $| = 1;

	open(STDIN, "<&parent1");
	open(STDOUT, ">&parent1");
	open(STDERR, ">&parent1");
	
	exec "./someprogram"; # should process the input and send it back to the parent
}
