LinuxQuestions.org
Review your favorite Linux distribution.
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 03-17-2009, 07:51 PM   #1
bt101
Member
 
Registered: Mar 2008
Posts: 56

Rep: Reputation: 18
What's the best way to run a conitnuous program at boot?


Hi - I need to run a program at boot. It is a perl script that talks to a serial device. The program needs to run forever (never stops). I see there are several ways to start such a program, but can't understand which is the best, especially considering that the program runs forever (not sure if that affects the decision).

I see there is:
-start it in rc.local
-start it in an init.d script
-start it with cron
-make a daemon

No matter what method is used, I am concerned as to whether I need to use an ampersand to run the program in the background so it will detach from the caller so that the caller does not get blocked (dunno if that matters). So I'm leaning to just using cron. If so, do I have it call a script with the ampersand (does it matter).

Thanks
 
Old 03-17-2009, 08:06 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,191

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
It would have been great if you had posted your distro, policy as where to put a program run a boot time varies from one distro to the other.

rc.local is a good candidate I would say.

The cleanest way to do this is like this:

- create a start/stop/restart script. Plenty of examples simple and complicated in init.d. You should be able to pick one and use it.

- it is best to call your script from the script mentioned above, and background it with '&'

- be sure your script does not produce output, or redirect it to /dev/null

- store the pid of the backgrounded process, and store the pid (in a file) so you are able to stop and restart the process. (you don't want to reboot your computer for that, do you?)

jlinkels
 
Old 03-17-2009, 11:23 PM   #3
bt101
Member
 
Registered: Mar 2008
Posts: 56

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by jlinkels View Post
It would have been great if you had posted your distro, policy as where to put a program run a boot time varies from one distro to the other.

rc.local is a good candidate I would say.

The cleanest way to do this is like this:

- create a start/stop/restart script. Plenty of examples simple and complicated in init.d. You should be able to pick one and use it.

- it is best to call your script from the script mentioned above, and background it with '&'

- be sure your script does not produce output, or redirect it to /dev/null

- store the pid of the backgrounded process, and store the pid (in a file) so you are able to stop and restart the process. (you don't want to reboot your computer for that, do you?)

jlinkels
Ah yes, good point... I'm running Ubuntu Server. No nice interface, but webmin is available for some config stuff. I was most worried about whether to run the script in the backgound (&), so it looks like I had better so it that way. I'll try as you recommend. Thanks.
 
Old 03-17-2009, 11:32 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,191

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
Once you created the script in init.d, don't forget to run update-rc.d to link the correct runlevels to the script. If Ubuntu works the same as Debian.

jlinkels
 
  


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
Program doesn't run properly on boot KenPem Programming 8 12-27-2007 05:42 PM
How to run a program at boot time crazylegs SUSE / openSUSE 2 12-12-2007 10:08 PM
How can a command/program be run automatically on boot? chuanweizuo Linux - Hardware 1 11-28-2005 11:36 AM
How do i have a program run at boot? ultramancool Linux - Software 4 02-25-2005 08:07 AM
How do I automatically run at boot an X program or script cmisip Linux - General 4 01-05-2003 07:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:23 AM.

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