#!usr/bin/perl -w |
my $pid = fork;
if $pid = 0) {
print "is parent\n";
} else {
# this is the child process
print "is child\n"; #子进程退出,会继续运行if一下的程序。
}
print 'program after "if"'."\n" #会打印两次,一次是父进程打印,一次是子进程打印的。
; exit 0; #子进程退出,不会运行if以后的程序 |
-w my $uid ="test 123"; pipe(CHILD_RDR, PARENT_WTR; my $pid ; $pid != 0) { #this is parent process close CHILD_RDR; print PARENT_WTR "$uid"; } else { # this is the child process close PARENT_WTR; $u = <CHILD_RDR>; print $u; } |
(PARENT_RDR; my $pid == 0this is child process close PARENT_RDR; print CHILD_WTR this is the parent process close CHILD_WTR<PARENT_RDR; } |
# pipe1 - bidirectional communication using two pipe pairs
# designed for the socketpair-challenged
use IO::Handle; # thousands of lines just for autoflush :-(
pipe(PARENT_RDR,CHILD_WTR); # XXX: failure?
pipe(CHILD_RDR,PARENT_WTR); # XXX: failure?
CHILD_WTR->autoflush(1);
PARENT_WTR->autoflush(1);
if ($pid = fork) {
#this is parent process
close PARENT_RDR; close PARENT_WTR;
print CHILD_WTR "Parent Pid $$ is sending this\n";
chomp($line = <CHILD_RDR>);
print "Parent Pid $$ just read this: `$line'\n";
close CHILD_RDR; close CHILD_WTR;
waitpid($pid,0);
}
else
{
#this is child process
die "cannot fork: $!" unless defined $pid;
close CHILD_RDR; close CHILD_WTR;
chomp($line = <PARENT_RDR>);
print "Child Pid $$ just read this: `$line'\n";
print PARENT_WTR "Child Pid $$ is sending this\n";
close PARENT_RDR; close PARENT_WTR;
exit;
}
#!/usr/bin/perl -w |
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。