What's the best way to run a conitnuous program at boot?
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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).
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
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?)
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.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.