LinuxQuestions.org
Help answer threads with 0 replies.
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, 06:51 PM   #1
bt101
Member
 
Registered: Mar 2008
Posts: 61

Rep: Reputation: 19
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, 07:06 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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, 10:23 PM   #3
bt101
Member
 
Registered: Mar 2008
Posts: 61

Original Poster
Rep: Reputation: 19
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, 10:32 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

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

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

All times are GMT -5. The time now is 04:41 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
Open Source Consulting | Domain Registration