Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5277579
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: LINUX

2010-12-30 09:28:13

[Perl]IPC进程间内存共享

#!/usr/bin/perl -w

#test_server run under administrator
use strict;
use IPC::Shareable;
my $glue = 'test.key';
my %options = (
    create => 1,
    exclusive => 0,
    mode => 0644,
    destroy => 1,
);
my @arr;
tie @arr, 'IPC::Shareable', $glue, { %options } or die "server: tie failed\n";
@arr = ();
while (1) {
        print "Input:";
        my $input=<STDIN>;
        chomp $input;
        if (defined $input) {
                push(@arr,$input);
        }
        print "\@arr:@arr\n";
}
exit;


 

 

#!/usr/bin/perl -w

#test_client run under administrator

use strict;
use IPC::Shareable;
my $glue = 'test.key';
my %options = (
    create => 0,
    exclusive => 0,
    mode => '0644',
    destroy => 0,
    size=>65536
#size must less then 65536
    );
my @arr;
my $ipch=tie @arr, 'IPC::Shareable', $glue, { %options } or die "client: tie failed\n";
while(1) {
        if (scalar @arr > 0) {
                $ipch->shlock;
                my $str=shift @arr;
                $ipch->shunlock;
                print "output:$str\n";
        } else {
                sleep 3;
        }
}
exit;

阅读(2067) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~