我正在尝试在 perl 中运行后台进程。我创建了一个子进程,用于调用另一个 perl 脚本。我想与这个子进程并行运行几行代码。子进程完成后。我想打印一行代码。
主要脚本
#!/usr/bin/perl
$|=1;
print "before the child process\n";
my $pid = fork();
if (defined $pid)
{
system("perl testing.pl");
}
print "before wait command\n";
wait();
print "after 20 secs of waiting\n";
测试.pl
#!/usr/bin/perl
print "inside testing\n";
sleep(20);
预期产出
before the child process
before wait command
(should wait for 20 secs and then print)
after 20 secs of waiting
你的脚本有很多问题。总是:
use strict;
use warnings;
local
设置特殊变量是一个很好的做法。仅包含特殊值的变量undef
返回 falsedefined
。因此,所有其他值(甚至是0
;这里的情况就是这样)返回 truedefined
。在另一个脚本中,shebang http://en.wikipedia.org/wiki/Shebang_%28Unix%29是错的。
#!/usr/bin/perl
use strict;
use warnings;
local $| = 1;
print "Before the child process\n";
unless (fork) {
system("perl testing.pl");
exit;
}
print "Before wait command\n";
wait;
print "After 20 secs of waiting\n";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)