Sh: 0: getcwd () failed: no such file or directory from exec command

I have a php server that runs some code in the background using Gearman server. The command line php script runs in the background. In the middle there is one server (walker) that is always running and listening for some events. When I listen to some particular event, it runs another command line command using php exec ("some command").

If this server is running fresh, then it works fine, but after a few hours it starts giving:

sh: 0: getcwd() failed: No such file or directory  

      

where we use exec ();

Any idea on how I can prevent this from happening?

+3


source to share


1 answer


This error indicates that it was getcwd()

returned NULL

from errno

set to ENOENT

.

getcwd()

will return ENOENT

if the current working directory has been detached. This appears to be here (according to the man page, this is the only condition that getcwd()

returns ENOENT

).



Double check to make sure no one has deleted the directory while the server is running, or if the server code itself does not call unlink()

in the current working directory. Someone, somewhere, deletes it.

As a good practice, it is often recommended for dismounted processes to chdir()

use a well-known directory in which the daemon will perform its duties. This is precisely to avoid such a problem (and also because a daemon running on a separate filesystem can prevent an administrator from unmounting that filesystem).

+2


source







All Articles