2009/8/19 liseen <[email protected]>:
> fork 之后各个进程的内存并不是共享的, 怎么能用这个方法呢, 呵呵。
>
>
> 2009/8/19 Haiyan Lin <[email protected]>
>>
>> 能不能具体一点,在楼顶的代码中加点示例代码。谢谢。
>>
其实看看模块的文档很容易搞的。
简单写个测试脚本仅供参考:
use strict;
use warnings;
use DB_File;
if ( fork ) { # in parent
for (1..30) {
increase();
sleep 1;
}
} else { # in child
for (1..30) {
sleep 1;
my %hash;
tie %hash, "DB_File", "a.db", O_RDONLY, 0444, $DB_HASH
or die "tie dbfile failed: $!\n";
print $hash{'test'},"\n";
untie %hash;
}
}
sub increase {
my %hash;
tie %hash, "DB_File", "a.db", O_RDWR|O_CREAT, 0666, $DB_HASH
or die "tie dbfile failed: $!\n";
$hash{'test'} ++;
untie %hash;
}
--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。
要在此论坛发帖,请发电子邮件到 [email protected]
要退订此论坛,请发邮件至 [email protected]
更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---