child.pl別のperlプログラムでperlプログラムを呼び出し、からにparent.plデータを渡し、によってこれらのデータを出力したいと思います。 parent.plは完了するまで何もしないため、機能しない可能性があります。perlipcのオンラインドキュメントを読みましたが、私のニーズの一部に一致するようですが、後に子プロセスから親にデータを渡す方法を見つけることができませんでした。これがのコードです:child.plparent.plparent.plsystem("perl child.pl")child.plpipe()fork()execparent.pl
#!/usr/bin/perl -w
pipe(FROM_CHILD, TO_PARENT);
$pid = fork();
if ($pid == 0) {
# We're in the child process.
close(FROM_CHILD);
# Send data to parent.
print TO_PARENT "Hello, parent\n"; # I can pass data to parent before exec
exec("perl child.pl"); # But how what should I do after exec, in child.pl?
exit(0); # Terminate child.
}
elsif (undef $pid) {
print "Not defined: means an error.";
}
else {
# Parent process.
close(TO_PARENT);
$data = <FROM_CHILD>;
print "From child: $data\n";
$id = wait();
print "Child $id is dead.\n";