Shell script hangs
Hi linux gurus and non gurus.
I have a little problem, hope I'll find a solution here.
Shell script hangs up periodically (after 1-3 weeks of work).
What can cause such behavior?
Content of the script is pretty simple:
an infinite loop in which every 2 seconds I call php script, thats it.
Is there any limitation for shell script execution time?
When I look into ps list it shows me that not only shell script but php script also hangs up. So can php script be the root of the problem?
Any advice, help, assumption will be appreciated.
Thanks in advance.
content of the script:
while [ 1 ];do
php -f /path/to/php/script.php
If "script.php" hangs, then the container script will hang also.
Would you mind to explain why when I kill script.php its container script doesn't resume normal operation?
Is it normal?
Well, one thing to check... Is the php instance going away?
Another possibility... Does the php script take longer than 2 seconds to run and are there things like locked files that might become a problem? One thing to try is to expand the sleep time to maybe 10 seconds. You can also use that to diagnose the problem by checking if the sleep is running in a ps.
Just some random thoughts.
Edit: Just realized you are not backgrounding the php script, so a previous run interfering isn't likely. But, if you use lock/run files or stuff like that, check to make sure you are cleaning them up right in all cases.
Maybe if the php script is the issue you should show what it contains?
The container script waits for script.php to finish. If you kill the latter, then that never happens.
In the container script, try adding "echo $?" after the call to script.php. This prints the return code from the php script. In normal operation, it should print "0" each time that script.php runs.
The script connects to broker gets latest quotes and writes them to DB,
and yes, sometimes it can take longer than 2 seconds to run.
But I guess this can't cause the problem... OR can???
Thanks for the idea ($?), I'll try to modify script a little bit
to report me if the script fails.
Will the call to script.php return anything if it hangs?
I mean will I be able to check the return code when script hangs?
If it is not possible to fix the php script so it doesn't hang, it is probably possible to program the shell script to kill it if it does not complete within a reasonable time (and to do any necessary cleaning up).
EDIT: in answer to "will I be able to check the return code when script hangs?" and presuming "script" here refers to the php script then no, you will not. A process running a hung script has not exited so has not set an exit code so has not set a return code (a return code is part of an exit code) so there is no return code to check.
Thanks for the advice I'll do it this way.
|All times are GMT -5. The time now is 01:50 PM.|