树莓派ZeroW学习笔记【3】程序自启动

已经编译好一个可执行程序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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值