LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-07-2010, 08:02 AM   #1
junior_unix_user
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Rep: Reputation: 0
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:

#!/bin/bash
while [ 1 ];do
php -f /path/to/php/script.php
sleep 2
done
 
Old 04-07-2010, 08:06 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
Quote:
So can php script be the root of the problem?
I would say **highly likely**......In your BASH script, there is not much to go wrong.
If "script.php" hangs, then the container script will hang also.
 
Old 04-07-2010, 08:24 AM   #3
junior_unix_user
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks.
Would you mind to explain why when I kill script.php its container script doesn't resume normal operation?
Is it normal?
 
Old 04-07-2010, 08:35 AM   #4
nuwen52
Member
 
Registered: Feb 2009
Distribution: CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 205

Rep: Reputation: 46
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.

Last edited by nuwen52; 04-07-2010 at 09:07 AM.
 
Old 04-07-2010, 08:41 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,655

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Maybe if the php script is the issue you should show what it contains?
 
Old 04-07-2010, 08:41 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
Just guessing:
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.
 
Old 04-07-2010, 09:22 AM   #7
junior_unix_user
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Original Poster
Rep: Reputation: 0
nuwen52, grail
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???

pixellany
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?

Thanks.

Last edited by junior_unix_user; 04-07-2010 at 09:25 AM.
 
Old 04-07-2010, 09:44 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
Quote:
Originally Posted by junior_unix_user View Post
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?
Experiments can be helpful:
Code:
c@CW8:~$ sleep 60 && echo true || echo non-zero return code $?
c@CW8:~$ ps -ef | grep sleep 60 | grep -v grep
c        10309 10183  0 19:05 pts/2    00:00:00 sleep 60
c@CW8:~$ kill 10309
Terminated
non-zero return code 143
The symptoms described in the OP are entirely consistent with the php script hanging so the quest for a solution is better directed at the php script than the shell script.

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.

Last edited by catkin; 04-07-2010 at 09:48 AM.
 
Old 04-07-2010, 09:53 AM   #9
junior_unix_user
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for the advice I'll do it this way.
 
  


Reply

Tags
hangs, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass variable from one shell script into another shell script xskycamefalling Programming 9 10-03-2009 02:45 AM
help with execute mulitple shell script within shell script ufmale Programming 6 09-13-2008 01:21 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
Shell script using nohup hangs lloracle_dba Programming 7 05-04-2005 11:52 AM


All times are GMT -5. The time now is 04:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration