已经编译好一个可执行程序main,存放的绝对路径/home/pi/T002_AS32_TTL/,希望开机能够自启动,可以通过如下方法实现:
通过修改rc.local文件,设置树莓派开机自动执行
1、编辑/etc/rc.local文件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23root@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、重启系统,就可以生效了
复制代码
1root@raspberrypi:~# reboot
最后
以上就是动人乌龟最近收集整理的关于树莓派ZeroW学习笔记【3】程序自启动的全部内容,更多相关树莓派ZeroW学习笔记【3】程序自启动内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复