此代码下载带有xmltv抓取器的EPG,并向tvtime(tvtime-command)发送命令,以便在OSD底部显示一条消息(等待几分钟,同时EPG更新...)。
如果程序tvtime没有运行,在tvtime中显示消息是无用的,我想停止父进程(向tvtime发送命令),而不杀死子(EPG更新......)以及如果tvtime稍后会打开孩子没有完成(EPG更新......),重启父进程(向tvtime发送命令)。
use strict;
use warnings;
use File::Temp qw(tempfile);
$tmp = new File::Temp( UNLINK => 0 );;
defined(my $pid = fork) or die "Couldn't fork: $!";
#child process
if ($pid == 0) {
system("tv_grab_fi | tv_sort >> $tmp");
my $HOME = $ENV{HOME};
system("mv $tmp $HOME/.xmltv/EPG.xml");
unlink($tmp);
exit;
}
use POSIX qw(:sys_wait_h);
#parent process
while (! waitpid($pid, WNOHANG)) {
system("tvtime-command DISPLAY_MESSAGE \'Wait several minutes while EPG updates...\'");
sleep 1;
}
由于
我的解决方案不是很明智:
#parent process
while (! waitpid($pid, WNOHANG)) {
open(PS, "ps aux | grep \[tv\]time |") || die "Can't open PS: $!\n";
while ( <PS> ) {
system("tvtime-command DISPLAY_MESSAGE \'Wait several minutes while EPG updates...\'");
sleep 1;
}
}