Perl守护程序不能与Sleep()一起使用 [英] Perl Daemon Not Working with Sleep()
本文介绍了Perl守护程序不能与Sleep()一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Proc编写了一个简单的测试守护程序: :守护进程。这是守护进程:
I wrote a simple test daemon using Proc::Daemon . Here is the daemon:
#!/usr/bin/perl
use Proc::Daemon;
$daemon = Proc::Daemon->new(
work_dir => '/scripts/',
child_STDOUT => '/scripts/child.log',
child_STDERR => '+>>debugchild.txt',
pid_file => 'pid.txt',
exec_command => 'perl /scripts/test.pl'
);
foreach(@ARGV)
{
if ( /install/i )
{
$Kid_1_PID = $daemon->Init;
}
elsif (/remove/i)
{
$stopped = $daemon->Kill_Daemon();
}
}
这是执行的测试:
#!/usr/local/bin/perl
while (1) {
print "test\n";
sleep(1);
}
while循环仅适用于print语句,但是当我添加睡眠时();日志为空。为什么会这样呢?
The while loop works fine with just the print statement, but when I add sleep(); the log is empty. Why would this be?
推荐答案
Perl不会自动刷新缓冲区,因此您对文件的写入将仅在相当一段时间后发生。当您没有睡眠时,由于要写入的数据量大,缓冲区将几乎自动刷新。
Perl will not automatically flush the buffer so your write to the file will only happen after quite a while. When you don't have the sleep your buffer will be almost automatically flushing due to the volume of data being written.
尝试以下操作:
$| = 1;
while (1) {
print "test\n";
sleep(1);
}
这篇关于Perl守护程序不能与Sleep()一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文