Difference in how system() and backticks execute commands 
Author Message
 Difference in how system() and backticks execute commands

I'm trying to chase a very weird problem with a program that is run by cron
on RH linux 2.0.34 with perl5 (5.0 patchlevel 4 subversion 4).  The problem
is that I have a command I execute in backticks and it is giving me back an
exit status of -1 [which means the 'wait()' system call failed] but when I
execute the *identical* shell command within a system(), it works fine.
and note that the backticks also work fine in EVERY test environment I've
been able to come up with: *only* when run out of cron does the anomaly
show up (making it a bear to debug and figure out what's going on). Anyhow,
to try to get a hint about what's happening, I'd like to know a bit about
what might be different in the way backticks are forked/waitedfor versus
the way system()'ed commands do it.

The code I'm looking at runs like this:

                                  # always the same problem!
    if ($? != 0)
    {
        warn "  exited $?: $!\n";

        warn "  System was OK\n"
            if system("same command, char-for-char") == 0;
        return undef ;
    }

What I get is interesting [maybe :o)] :

  exited -1: No child processes
  output was <correct output from the program>
  Second time got status -1
[output appears here, again, from system sending it to stdout]
  System was OK

So, I thinks: something in the process environment that cron sets up [and
ONLY cron, at least as far as I understand it now] has the effect that
however Perl does backticks somehow loses the child process, but the child
process is OK for a 'system' of the identical command.  I'm working on the
differences from the cron side [I'm trying to duplicate the 'cron'
environment, piece by piece, to see if/how I can produce the same
behavior], but I'd also appreciate info about this from the other side of
the fence: what differences there are in how Perl does the fork/wait that
might give me a hint as to what cron is doing to mess it up.

Thanks!
  /Bernie\
--
Bernie Cosell                     Fantasy Farm Fibers

    -->  Too many people, too few sheep  <--          



Sun, 11 Nov 2001 03:00:00 GMT  
 Difference in how system() and backticks execute commands

Quote:

} I'm trying to chase a very weird problem with a program that is run by cron
} on RH linux 2.0.34 with perl5 (5.0 patchlevel 4 subversion 4).  The problem
} is that I have a command I execute in backticks and it is giving me back an
} exit status of -1 ... but when I
} execute the *identical* shell command within a system(), it works fine.
} [...]
} to try to get a hint about what's happening, I'd like to know a bit about
} what might be different in the way backticks are forked/waitedfor versus
} the way system()'ed commands do it.

As a small addendum to this, there are two other ways to do a backtick
operation: one is via open-from-a-pipe, and the other is by explicit
fork/exec/pipe.  So for the first step I did:

Quote:
} sub backtick
} {


}     close B or warn $! ? "Got error $! in backtick\n"
}                        : "Exited with $? status from backtick\n" ;


} }

And sure enough, got the same error [no child processes].  So whatever
crond has done to its environment, it has broken *both* backticks and
open-from-a-pipe.  I'll investigate the explicit fork/pipe/wait approach
anon...

Someone suggested that it could have something to do with SIGCHLD.  Is
anyone out there familiar enough with the Perl fork-handling code for
backticks and read-from-pipe to know if something messed up in the
execution environment for SIGCHLD [or anything like that] could mess up the
'wait' for the child process?  [could perl possibly get both a SIGPIPE and
a SIGCHILD, and try to do 'wait's in both paths or something like that [but
only when run from crond...sigh...]]

  /bernie\
--
Bernie Cosell                     Fantasy Farm Fibers

    -->  Too many people, too few sheep  <--          



Sun, 11 Nov 2001 03:00:00 GMT  
 Difference in how system() and backticks execute commands

+-----
| I'm trying to chase a very weird problem with a program that is run by cron
| on RH linux 2.0.34 with perl5 (5.0 patchlevel 4 subversion 4).  The problem
| is that I have a command I execute in backticks and it is giving me back an
| exit status of -1 [which means the 'wait()' system call failed] but when I
+--->8

This is a bug in Red Hat 5.x's vixie-cron package:  it sets SIGCHLD to SIG_IGN,
which is inherited by the cron job.  Get the fixed vixie-cron package from
updates.redhat.com.

--


carnegie mellon / electrical and computer engineering                    KF8NH
                          Kiss my bits, Billy-boy.



Sun, 11 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Executing commands via backticks

2. returning output from commands executed with backticks

3. RE : DIFFICULT: Can't execute system command from FVWM, but can from the command line

4. pipe problem in backticks/system command

5. backticks/system command

6. Executing system commands

7. Executing System Command as Another User

8. Perl system command and NT not executing properly...

9. capturing output of executed system command

10. Executing multiple system commands

11. Perl script to execute a command on the least loaded system

12. Executing system commands

 

 
Powered by phpBB® Forum Software