Linux下如何实现程序的开机自启动??

时间:2022-01-04 02:13:29
比如说,我写了一个helloworld.c程序,编译后的可执行程序helloworld放在/home/myprogram目录下。
那么我该如何实现开机启动该程序呢?谢谢

12 个解决方案

#1


 cat /etc/inittab  查看系统启动的运行级别。
如果启动级别为5 则
cd /etc/rc.d/rc5.d

建立脚本:S99hello
#! /bin/bash
#file: S99hello

/home/myprogra/helloword &

#2


你在/etc/init.d写个脚本
比如:
auto-start.sh

#!/bin/bash
/home/myprogram/helloworld


然后在/etc/rc2.d中
写个软连接
比如叫
ln -s /etc/init.d/auto-start.sh S60autostart 
就Okay了

你ls 下会看见 S60autostart--->auto-start.sh

reboot下你的系统 你就能开机启动 helloworld了

#3


谢谢,学习了

#4


再次学习了

#5


rc2.d/rc3.d/rc5.d好像都是启动的脚步(级别不同),以S开头
rc0.d/rc6.d都是关闭的脚步(级别不同),以K开头

文件S或K后面的数字是执行顺序,由小到大依次执行。
所以一般自己写的脚步或者程序如果对系统服务没有依赖关系的,可以随便放。但建议尽量往后排放。

#6


在etc/rc.local里面加一行
/home/myprogram/helloword &

#7


写一个可执行的script,调用你的程序,注意要用完整路径,然后放到/etc/rcX.d目录下就可以了

#8


引用 1 楼 pottichu 的回复:
cat /etc/inittab  查看系统启动的运行级别。 
如果启动级别为5 则 
cd /etc/rc.d/rc5.d 

建立脚本:S99hello 
#! /bin/bash 
#file: S99hello 

/home/myprogra/helloword & 


引用 6 楼 disikj 的回复:
在etc/rc.local里面加一行 
/home/myprogram/helloword &


都可以

#9


http://blog.chinaunix.net/u1/54869/showart_441803.html

好好看完这篇文章吧,很详细的。

#10


引用 9 楼 hairetz 的回复:
http://blog.chinaunix.net/u1/54869/showart_441803.html 

好好看完这篇文章吧,很详细的。


确实很全面了

#11


学习

#12


好东西,很详细

#1


 cat /etc/inittab  查看系统启动的运行级别。
如果启动级别为5 则
cd /etc/rc.d/rc5.d

建立脚本:S99hello
#! /bin/bash
#file: S99hello

/home/myprogra/helloword &

#2


你在/etc/init.d写个脚本
比如:
auto-start.sh

#!/bin/bash
/home/myprogram/helloworld


然后在/etc/rc2.d中
写个软连接
比如叫
ln -s /etc/init.d/auto-start.sh S60autostart 
就Okay了

你ls 下会看见 S60autostart--->auto-start.sh

reboot下你的系统 你就能开机启动 helloworld了

#3


谢谢,学习了

#4


再次学习了

#5


rc2.d/rc3.d/rc5.d好像都是启动的脚步(级别不同),以S开头
rc0.d/rc6.d都是关闭的脚步(级别不同),以K开头

文件S或K后面的数字是执行顺序,由小到大依次执行。
所以一般自己写的脚步或者程序如果对系统服务没有依赖关系的,可以随便放。但建议尽量往后排放。

#6


在etc/rc.local里面加一行
/home/myprogram/helloword &

#7


写一个可执行的script,调用你的程序,注意要用完整路径,然后放到/etc/rcX.d目录下就可以了

#8


引用 1 楼 pottichu 的回复:
cat /etc/inittab  查看系统启动的运行级别。 
如果启动级别为5 则 
cd /etc/rc.d/rc5.d 

建立脚本:S99hello 
#! /bin/bash 
#file: S99hello 

/home/myprogra/helloword & 


引用 6 楼 disikj 的回复:
在etc/rc.local里面加一行 
/home/myprogram/helloword &


都可以

#9


http://blog.chinaunix.net/u1/54869/showart_441803.html

好好看完这篇文章吧,很详细的。

#10


引用 9 楼 hairetz 的回复:
http://blog.chinaunix.net/u1/54869/showart_441803.html 

好好看完这篇文章吧,很详细的。


确实很全面了

#11


学习

#12


好东西,很详细