perl 消息队列
Posted longchang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了perl 消息队列相关的知识,希望对你有一定的参考价值。
#!/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. "; } elsif ($pid == 0) { print "I am the child. "; sleep 3; print "I am the child 1.1. "; $queue->snd($msgtype, $msgdata); print "I am the child 1.2. "; sleep 2; print "I am the child 2. "; exit(0); } else { print "I am the parent 1. "; $type = $queue->rcv($buf, 256); print "I am the parent 2. "; print "type => $type. "; $ds = $queue->stat; print $buf; print $ds; print "end pid => $pid. "; $res = $queue->remove; print "remove res => $res. "; if (!defined $res) { print "hello => $!. "; } waitpid($pid, 0); }
子进程发送消息,父进程接收消息。其中queue->rcv是阻塞的。
以上是关于perl 消息队列的主要内容,如果未能解决你的问题,请参考以下文章