概述
已经编译好一个可执行程序main,存放的绝对路径/home/pi/T002_AS32_TTL/,希望开机能够自启动,可以通过如下方法实现:
通过修改rc.local文件,设置树莓派开机自动执行
1、编辑/etc/rc.local文件
root@raspberrypi:~# vim /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %sn" "$_IP"
fi
./home/pi/T002_AS32_TTL/main &
exit 0
注意点:
【1】在文件中的 exit 0 之前添加需要执行的程序,注意要使用绝对路径。
【2】如果程序是阻塞型的,也就是程序会一直不停的执行,则须加上 & 符号,使程序以后台运行的方式执行,否则系统会卡在这一步无法继续启动。
2、重启系统,就可以生效了
root@raspberrypi:~# reboot
最后
以上就是动人乌龟为你收集整理的树莓派ZeroW学习笔记【3】程序自启动的全部内容,希望文章能够帮你解决树莓派ZeroW学习笔记【3】程序自启动所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复