LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-11-2006, 11:16 PM   #1
masea2
LQ Newbie
 
Registered: Nov 2006
Posts: 2

Rep: Reputation: 0
Question Bash script hangs upon starting another script in the background


Hi,

I am trying to create a program that I will use to start a vendor application, but once I kick off that application my script just hangs...

here is what the relevant part of my script looks like:
pid=`/usr/bin/nohup./hawkagent_$bwdom &`
exit 0

When executing this with the -x option I see my script is just hanging on this line:
++ ./hawkagent_BWDEXPMGMT

Any ideas?
 
Old 11-12-2006, 12:55 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
I think it has to do with the fact that you are assigning its output to a variable (assuming those are backticks in your post). A quickie experiment I just ran (using ls and sleep) seems to indicate that in this case, even though the process does get run in the background, the script won't proceed until it can assign the value.
 
Old 11-12-2006, 06:12 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Looks like you're working with some batch system. BWDEXPMGMT looks like a maestro job name to me! MGMT = management? EXP = export? BWD? Hmm. I've spent way too long in the past trying to work out the purpose of some undocumented job from the job name. *sigh*

ANYhow... There are a few things which are wrong here.
  • I think you want a space between /usr/bin/nohup and the command name "./hawkagent_$bwdom". If this is a typo, please please please - when putting failing example code into the forums copy-paste it. If that's not possible for some reason, at least copy it carefully.
  • You can't do backgrounding with `command substitution`. Well, you can but only in order to run multiple commands within that command substitution. The `` statement will wait until all processes spawned by the `` have completed before returning. This makes sense because the `` evaluates to the output of the commands in the back-quotes, so it can't know what the output is until the command is complete.
If you want to get the PID of the backgrounded process, try this. Note it will only work if you only have one backgrounded process from the script:
Code:
nohup /usr/bin/nohup ./hawkagent_$bwdom &
pid=`jobs -p`
...
By the way, when trying to make daemon processes, please consider following the advice in this document. There's a right way of making daemon processes, and "nohup command &" isn't it!
 
Old 11-12-2006, 10:51 PM   #4
masea2
LQ Newbie
 
Registered: Nov 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Cool Found a solution

The way to resolve it is as follows:

(./hawkagent_BWDEXPMGMT > $Logs/Hawk.log 2>&1 &) &

Double backgrounding of process seems to work.
 
Old 11-13-2006, 05:18 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Quote:
Originally Posted by masea2
The way to resolve it is as follows:

(./hawkagent_BWDEXPMGMT > $Logs/Hawk.log 2>&1 &) &

Double backgrounding of process seems to work.
That's really ugly, and you don't have the PID of the backgrounded process. Also, it is not a proper daemon process - the process still has a filehandle open to the pwd (this should be changed to /) etc...
 
  


Reply


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
bash, starting a command in script activeq Programming 9 07-27-2006 08:42 AM
BASH script for starting printer ylikone Programming 2 06-01-2006 04:56 AM
bash script to accept input ONLY until background process completes andrewstr Linux - Software 2 03-17-2004 12:02 PM
Starting a service in a bash script AMMullan Programming 3 02-19-2004 11:06 AM
How to run a bash command in the background from perl script professorfrink Programming 3 11-13-2003 03:02 PM


All times are GMT -5. The time now is 12:56 AM.

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