Reputation: 1117
I have a php server running some code in background using Gearman server. The command line php script is running in the background. In the middle, there is one server (walker) which is always running and listening to some events. When I listen to some specific event it fires another command line command using php exec ("some command").
If this server is running fresh, then it works ok, but after some hours it starts giving:
sh: 0: getcwd() failed: No such file or directory
where we use exec();
Any idea on how can I prevent this?
Upvotes: 4
Views: 6368
Reputation: 21213
This error indicates that getcwd()
returned NULL
with errno
set to ENOENT
.
getcwd()
will return ENOENT
if the current working directory was unlinked. This seems to be the case here (according to the manpage, that's the only condition that causes getcwd()
to return ENOENT
).
Double check to make sure that no one deleted the directory while the server is running, or if the server code itself doesn't call unlink()
on the current working directory. Someone, somewhere, is deleting it.
As a good practice, it is often recommended for daemonized processes to chdir()
to a known directory where the daemon will perform its duties. This is precisely to avoid this sort of problem (and also because a daemon running in a separate filesystem could prevent the administrator from unmounting that filesystem).
Upvotes: 3