English 中文(简体)
为什么在使用LibXML之后,Perl坠毁?
原标题:Why does Perl crash when using LibXML after a fork?
  • 时间:2011-11-03 20:19:56
  •  标签:
  • perl

我花了很强的时间处理这个问题,但我把这个问题缩小到使用XML:LibXML,在我去Perl做过 for后。 视窗XP和XML:LibXML 1.70。

我有一份文字,我需要同时管理几个进程,掌握XML的产出并处理结果。 如果我用太阳能机器操作,那就算是罚款,我没有问题。 然而,如果我在Windows上运行,我就有一个坠毁的窗口,称其永久。 外部遇到问题,需要结束。

这里是产生错误的样本方案:

use strict;
use warnings;
use XML::LibXML;
use Try::Tiny;

my $cmds = [ cmd1 ,  cmd2 ];
my @pids = ();
foreach my $cmd (@{$cmds}) {

    my $pid = fork();

    if ($pid) {

        # parent
        push (@pids, $pid);
    } elsif ($pid == 0) {

        XML::LibXML->load_xml(string=> <root /> ); # <-- this will crash it
        exit 0;
    }
}

foreach my $ch_pid (@pids) {

    try {

        waitpid($ch_pid, 0);
    } catch {

        carp("Error on waitpid: $!");
    };
}
exit 0;

If I only have one process, or if I don t fork, then it will work successfully. If I remove the load_xml call (and have nothing in the child), then it will work successfully.

Does anyone know what may be causing this and how to fix it?

最佳回答
问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签