0

I am using exec() inside a a script that runs as a daemon and forks child processes using the pear class Net_Server.

I am getting a strange issue whereby the return code (the third param of of exec) comes back as -1. When I run the command on the command line, or with exec in a normal php script the return code is 0 as it should be. Anyone have any idea why this is happening, and how to fix it?

1
  • Does that code use pcntl_signal() by any chance? Commented Jun 17, 2010 at 16:40

2 Answers 2

1
 pcntl_signal(SIGCHLD, SIG_DFL);
 exec('...');
 pcntl_signal(SIGCHLD, 'whatever it was');
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, that worked. The pear class was setting pcntl_signal(SIGCHLD, SIG_IGN);
Could you please give a bit more info about the 'whatever it was' part? How do I know what should I put there? Thanks
@gabo: whatever it was it just that, the problem of the original asker was that something was overriding the default signal handler for SIGCHLD with 'something'. The solution for him was going back to the default SIG_DFL for what he needed to do, and after that set the signal handler for SIGCHLD back to whatever it was overriden with in the first place (likely for a good reason). No way to tell what that was in the code. If you use a specific signal handler instead of the deafult, you most will know what that is in your code unless your using undocumented 3rd party code.
0

I guess it is an issue with environment variables. Maybe the thing you are trying to execute is normally in your PATH, but not when you spawn a daemon. Supply the full path to the program.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.