Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No child processes" error in perl

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?

like image 352
Vivek Avatar asked Dec 09 '25 23:12

Vivek


1 Answers

On most Unix platforms, the CHLD (sometimes also known as CLD) 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 to wait() on its child processes (i.e. child processes are automatically reaped). Calling wait() 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 to IGNORE probably by sqlldr. When you attempt to check on the status of the child process you receive the -1 which is sometimes referred to as ECHILD. This occurs because the information about the completion status of the child process has been discarded due to the ignoring of the CHLD 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.

like image 127
dave Avatar answered Dec 11 '25 12:12

dave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!