树莓上PI自动运行的C程序 [英] Auto-Running a C Program on Raspberry PI
问题描述
我怎样才能使我的C code到自动运行我的树莓PI?我见过一个教程,以实现这一点,但我真的不知道我仍下落不明。我的初始化脚本显示,因为它如下:
how can I make my C code to auto-run on my Raspberry PI? I have seen a tutorial so as to achieve that but I do not really know what I am still missing. My initialization script is shown as it follows:
#! /bin/sh
# /etc/init.d/my_settings
#
# Something that could run always can be written here
### BEGIN INIT INFO
# Provides: my_settings
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Script to start C program at boot time
# Description: Enable service provided by my_settings
### END INIT INFO
# Carry out different functions when asked to by the system
case "$1" in
start)
echo "Starting RPi Data Collector Program"
# run application you want to start
sudo /home/pi/Documents/C_Projects/cfor_RPi/charlie &
;;
stop)
echo "Killing RPi Data Collector Program"
# kills the application you want to stop
sudo killall charlie
;;
*)
echo "Usage: /etc/init.d/my_settings {start | stop}"
exit 1
;;
esac
exit 0
问题是,我的程序不会在系统启动时运行,我真的不知道为什么。什么会我丢失?这是killall语句中的执行时间杀了一些有用的过程?我提出这个code作为后台应用程序运行,但我知道,几秒钟后,当RPI初始化,它以初始化会话请求的用户名和密码。难道我的RPI没有执行此code,因为我没有提供日志信息?我没有显示器,使我的程序必须运行一次我插入我的Rp的。谢谢你在前进!
The problem is that my program does not run at boot time and I do not really know why. What would I be missing? Is this "killall" statement "killing" some useful process during execution time? I am making this code to run as a background application but I know that after a few seconds, when the RPi is initializing, it asks for an username and a password in order to initialize the session. Is it possible that my RPi is not executing this code because I am not providing the logging information? I do not have a monitor so that my program has to run once I plug my Rpi in. Thanks a lot in advance!!
推荐答案
如何脚本/服务是在startuptime运行,通常取决于所使用的初始化系统的类型。关闭我的头顶,我distginguish以下4种类型:
How scripts/services are run at startuptime, generally depends on the type of init system used. Off the top of my head, I'd distginguish the following 4 types:
- 嵌入式风格:一个shell脚本,拥有所有启动系统的命令。通常脚本是一关内核试图开始为init进程的路径。
- BSD风格的
- System V的风格:它使用/ etc / inittab中和latr脚本/etc/rc*.d/一个启动的服务之一
- systemd
Raspbian dervices,所以我想System V的风格。你必须符号链接你的脚本/etc/rc2.d中像
Raspbian dervices from Debian, so I suppose System V style. You have to symlink your script to /etc/rc2.d like
ln -s /etc/init.d/your-script /etc/rc2.d/S08my-script
链接名称的不是结构:它说,在进入运行级别时,就应该开始,而'08'确定的位置(做一个LS /etc/rc2.d/看到其他链接)
Not the structure of the link name: It says, it should be started when the run level is entered, and the '08' determines the position (do a ls /etc/rc2.d/ to see the other links).
更多细节:的init(8)
More details: init(8).
更新-的rc.d(8)是正确的WWAY到Debian上创建符号链接。请参阅手册页:
update-rc.d(8) is the proper wway to create the symlinks on debian. See the manpage:
update-rc.d - install and remove System-V style init script links
我建议至少阅读手册页更新-的rc.d(8)和init(8)。
I advice to read at least the man pages update-rc.d(8) and init(8).
这篇关于树莓上PI自动运行的C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!