“没有子进程” Perl 中的错误
我有一个 Perl 脚本,它调用 sqlldr 并将数据从平面文件加载到表中。
现在,我的问题是,即使 sqlldr 加载表正常,当我尝试使用 $!
时,它仍将退出代码返回为 -1(通过使用 $?
获得)它说没有子进程
。
我正在使用 sudo 命令执行此脚本
sudo -u <uname> bash
<script_name>.pl
如果我直接从我的用户 ID 执行此 Perl 脚本,则它可以正常工作。我真的不明白为什么只有当我通过 sudo 用户执行时才会出现此错误。
请帮助我理解这个错误。
编辑:如果我在代码中给出 $SIG{CHLD} = 'DEFAULT';
,则工作正常。但是,如果我删除这一步,问题就会再次出现。当我浏览此错误时,我从 WWW 获得了此代码。知道它有什么作用吗?
I have a Perl script which invokes the sqlldr and loads data to a table from a flat file.
Now, my problem is, even though the sqlldr loads the table fine it is returning exit code as -1(got by using $?
), when i tried using $!
it says No child processes
.
I'm executing this script by using sudo
command
sudo -u <uname> bash
<script_name>.pl
This Perl script is working fine if i execute it directly from my user id. I really don't understand why this error shows up only when i execute through sudo user.
Please help me to understand this error.
EDIT:It's working fine if i give $SIG{CHLD} = 'DEFAULT';
in my code. But, if i remove this step, the problem shows up again. I got this code from WWW when i was browsing about this error. Any idea what it does?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在大多数 Unix 平台上,
CHLD
(有时也称为CLD
)信号对于'IGNORE'
值具有特殊行为。在此类平台上将$SIG{CHLD}
设置为'IGNORE'
具有在父进程未能wait() 其子进程(即自动收获子进程)。在此类平台上,调用
wait()
并将$SIG{CHLD}
设置为'IGNORE'
通常会返回-1
.摘自http://perl.active-venture.com/pod/ perlipc-signal.html
基本上,发生的情况是
CHLD
信号已被设置为IGNORE
可能是由 sqlldr。当您尝试检查子进程的状态时,您会收到-1
,有时称为ECHILD
。发生这种情况是因为有关子进程完成状态的信息由于忽略CHLD
信号而被丢弃。通过设置 $SIG{CHLD} = 'DEFAULT'; 您表明 CHLD 信号应由 DEFAULT 处理程序处理而不是被忽略。我不知道为什么当从 sudo 用户执行脚本而不是直接从您的用户 ID 执行脚本时,
CHLD
信号被忽略。On most Unix platforms, the
CHLD
(sometimes also known asCLD
) signal has special behavior with respect to a value of'IGNORE'
. Setting$SIG{CHLD}
to'IGNORE'
on such a platform has the effect of not creating zombie processes when the parent process fails towait()
on its child processes (i.e. child processes are automatically reaped). Callingwait()
with$SIG{CHLD}
set to'IGNORE'
usually returns-1
on such platforms.Excerpted from http://perl.active-venture.com/pod/perlipc-signal.html
Basically what is happening is that somewhere the
CHLD
signal has been set toIGNORE
probably by sqlldr. When you attempt to check on the status of the child process you receive the-1
which is sometimes referred to asECHILD
. This occurs because the information about the completion status of the child process has been discarded due to the ignoring of theCHLD
signal. By setting$SIG{CHLD} = 'DEFAULT';
you are indicating that the CHLD signal should be handled by the DEFAULT handler and not ignored.I do not know why the
CHLD
signal is being ignored when the script is executed from sudo user versus being executed directly from your user id.