已经编译好一个可执行程序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 %s\n" "$_IP"
fi
./home/pi/T002_AS32_TTL/main &
exit 0
注意点:
【1】在文件中的 exit 0 之前添加需要执行的程序,注意要使用绝对路径。
【2】如果程序是阻塞型的,也就是程序会一直不停的执行,则须加上 & 符号,使程序以后台运行的方式执行,否则系统会卡在这一步无法继续启动。
2、重启系统,就可以生效了
root@raspberrypi:~# reboot