标签:== wait child type bsp private gty nbsp 发送消息
#!/usr/bin/perl use IPC::SysV qw(IPC_PRIVATE IPC_CREAT S_IRWXU); use IPC::Msg; my $queue = IPC::Msg->new(IPC_PRIVATE, S_IRWXU | IPC_CREAT); $msgtype = 6; $msgdata = "hello world!"; my $pid = fork(); if (not defined $pid) { print "resources not available.\n"; } elsif ($pid == 0) { print "I am the child.\n"; sleep 3; print "I am the child 1.1.\n"; $queue->snd($msgtype, $msgdata); print "I am the child 1.2.\n"; sleep 2; print "I am the child 2.\n"; exit(0); } else { print "I am the parent 1.\n"; $type = $queue->rcv($buf, 256); print "I am the parent 2.\n"; print "type => $type.\n"; $ds = $queue->stat; print $buf; print $ds; print "end pid => $pid.\n"; $res = $queue->remove; print "remove res => $res.\n"; if (!defined $res) { print "hello => $!.\n"; } waitpid($pid, 0); }
子进程发送消息,父进程接收消息。其中queue->rcv是阻塞的。
标签:== wait child type bsp private gty nbsp 发送消息
原文地址:https://www.cnblogs.com/longchang/p/12015769.html