【发布时间】:2014-06-28 11:37:29
【问题描述】:
我有一个以 root 身份运行的 perl 脚本,它监视串行设备并向其发送命令。在 apache 下,我有另一个 perl 脚本,它显示控制“根”脚本的 gui。
我试图通过 sigint 和 sigusr1 中断来自 gui perl 脚本的 root perl 脚本,但不允许进行操作,可能因为一个是 root,另一个不是。
我基本上希望 gui 能够告诉控制根脚本将一些命令传递给串行设备。
如果我以 root 身份从 cmd 行运行 gui 脚本,它可以成功地向 root 脚本发出信号
我不知道从哪里开始,有什么建议可以在不以 root 身份运行时中断 root 脚本的方法吗?如图所示调用单独的“信号”脚本:
@cmds = ("perl /var/www/signal.cgi", "$perlSerialPID", "test");
if (0 == system(@cmds)) {
# code if the command runs ok
print "system call ok: $?";
} else {
# code if the command fails
print "not ok $?";
}
# try backticks
$output = `perl /var/www/signal.cgi $perlSerialPID test`;
print "<br>:::$output";
信号.cgi:
#!/usr/bin/perl
$pid = $ARGV[0];
$type = $ARGV[1];
if($type eq "test"){
if(kill 0, $pid) {
print "perl-serial $pid running!";
}else{
print "perl-serial $pid gone $!";
}
}elsif($type eq "USR1"){
if(kill USR1, $pid) {
print "perl-serial interrupted";
}else{
print "perl-serial interrupt failed $!";
}
}else{
print "FAILED";
}
【问题讨论】:
-
制作一个发送信号的脚本。使用 sudo 以 root 身份调用该脚本。
-
如上所述gui脚本是在apache下运行的,那么你如何使用sudo按照你的建议调用它?
标签: apache perl signals interrupt