Why what happens? Perl run's "date", then returns when date exits,
after which it proceeds to die....perl is reporting that it die()ed.
I'm not sure what you expected to happen.
He was expecting the value returned by system() to be the same
as what gets stored in $? (zero on success, nonzero on failue).
But that is no longer the case; system() is returning -1 regardless
of the command's exit code.
solaris% perl -le '$SIG{CHLD} = "DEFAULT";print(system("/bin/true"))'
0
solaris% perl -le '$SIG{CHLD} = "DEFAULT";print(system("/bin/false"))'
65280
solaris% perl -le '$SIG{CHLD} = "IGNORE";print(system("/bin/true"))'
-1
solaris% perl -le '$SIG{CHLD} = "IGNORE";print(system("/bin/false"))'
-1
This behavior is not explictly documented; you have to do some digging
to see why the return value if system() has become misleading or useless.
From 'perldoc -f system':
The return value is the exit status of the program as returned
by the "wait" call. To get the actual exit value shift right
by eight (see below). Return value of -1 indicates a failure
to start the program (inspect $! for the reason).
From 'perldoc perlvar':
Using a value of 'IGNORE' usually has the effect of
ignoring the signal, except for the "CHLD" signal.
See perlipc for more about this special case.
From 'perldoc perlipc':
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.
That means that 'perldoc -f system' should have said:
The return value is what is returned by the "wait" call,
which the program's exit status. (Except when $SIG{CHLD}
is set to 'IGNORE', in which case system() returns -1.)
Conclusion: If it is possible that your program will be running with
a non-default value of $SIG{CHLD}, you'll have to change your
program logic to not look at the return value from system().
Change
system($command) and die;
to
system($command); $? and die;
-Joe