LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-21-2006, 04:46 PM   #1
sedan258
LQ Newbie
 
Registered: Sep 2006
Posts: 5

Rep: Reputation: 0
Wink How to start 2 background program at startup, one depends on the other?


Hello all, this is my first post :->

I wanted to start two background programs, at level 2 I think, during startup. I can make one work by putting the script into /etc/init.d folder and creating a link under /etc/rc2.d/.

Now, the problem is I wanted to start another background program, which can only be successful if the first one is started already. Actually, this is a socket based program. The first one hosts a server on a certain port and the second subscribes as a client to the same port. I tried to assigned the second program bigger value, e.g. S97FirstScript and S98SecondScript, but it didn't work.

Can any one help me out here? Thanks very much.
 
Old 09-21-2006, 05:26 PM   #2
pda_h4x0r
Member
 
Registered: Feb 2006
Location: somewhere in cyberspace
Distribution: Debian, Familiar
Posts: 380

Rep: Reputation: 30
It may be possible that the first background program is still being launched by the time the second program's script is run. Your second script should check to see if the first is running, and possibly wait a few seconds to allow it to initilize completely before giving up.
 
Old 09-21-2006, 05:43 PM   #3
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Rep: Reputation: 30
I've just gone blank, but I think you could do something like this...

Code:
/start/process/one && /start/process/two
The && will run the next command if the result from the first command is true.

Someone please correct me if I'm wrong.

-Kristijan
 
Old 09-21-2006, 11:49 PM   #4
sedan258
LQ Newbie
 
Registered: Sep 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Since the first one is a background program, I don't think it is going to return any value before it terminates.

I also tried to sleep 20 seconds before I execute the second program. Failed too.

Quote:
Originally Posted by Kristijan
I've just gone blank, but I think you could do something like this...

Code:
/start/process/one && /start/process/two
The && will run the next command if the result from the first command is true.

Someone please correct me if I'm wrong.

-Kristijan
 
Old 09-22-2006, 04:20 AM   #5
chingadero
LQ Newbie
 
Registered: Nov 2005
Posts: 10

Rep: Reputation: 0
This may not be the most elegant method, but I had the same situation.
I added "sleep 15" to the beginning of my start function in /etc/init.d/SecondScript so that it would wait 15 seconds before starting up.
 
Old 09-22-2006, 08:30 PM   #6
sedan258
LQ Newbie
 
Registered: Sep 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the reply. It is getting strange. In order to verify that it is actually getting executed, I put "sleep 300" before the second program. It did getting executed. After it gets started, I "ps -A" and found that the first program is running as a background program and the shell for the second program is running as well. Or actually, "sleep" is running. However, after "sleep" was finished, the second one kind of failed to run as a background program.

Again, the first one is socket server and the second is a client based on that.

Interestingly, I copy the line in the second shell and run it manually as background, it works. It seems that the system doesn't want to run it at start up. The command I was using is like:

"/absolute/location/second > /dev/null &"

Any idea about what is going wrong? Thanks.

Quote:
Originally Posted by chingadero
This may not be the most elegant method, but I had the same situation.
I added "sleep 15" to the beginning of my start function in /etc/init.d/SecondScript so that it would wait 15 seconds before starting up.
 
  


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
running java program at startup in background Maverick1182 Linux - Newbie 4 09-19-2006 07:09 PM
How Do I Get A Program to Start at the Machine Startup andy1.52 Linux - Software 1 03-03-2005 10:33 AM
start program on startup HTS Programming 2 07-08-2004 01:22 AM
how to make a program start on startup Maver Linux - Software 9 06-13-2004 06:54 PM
start a program at startup. abhay Slackware 3 10-14-2003 02:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration