【发布时间】:2021-03-17 18:44:52
【问题描述】:
我无法从 /etc/rc.local 运行某些进程。在提示符下,应用程序或命令行可以工作。我根据另一篇文章在c中做了一个简单的应用程序,并且该过程没有执行。我做错了什么?
诸如“insmod /home/root/ov5640.ko”之类的其他进程也仅在从命令行或从提示符执行的应用程序执行时才有效,但不能直接从/etc/rc.local执行,女巫返回insmod 作为一个无法识别的命令。
感谢您的帮助。
// can_init.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc,char* argv[]){
int status;
// By calling fork(), a child process will be created as a exact duplicate of the calling process.
// Search for fork() (maybe "man fork" on Linux) for more information.
if(fork() == 0){
// Child process will return 0 from fork()
printf("I'm the child process.\n");
status = system("ifconfig can0 down");
status = system("ip link set can0 type can tq 400 prop-seg 3 phase-seg1 8 phase-seg2 8 sjw 4");
status = system("ip link set can0 type can restart-ms 100");
status = system("ifconfig can0 up");
status = system("ip -details -statistics link show can0");
exit(0);
}else{
// Parent process will return a non-zero value from fork()
printf("I'm the parent.\n");
}
printf("This is my main program and it will continue running and doing anything i want to...\n");
return 0;
}
/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.
echo 30000 > /proc/sys/vm/min_free_kbytes
echo "0" > /sys/class/graphics/fb0/blank
/home/root/can_init >/dev/null 2>&1 &
echo "test 2"
exit 0
【问题讨论】:
-
ls -l /etc/rc.local的输出是什么?是否已成为可执行文件? -
ifconfig和ip在/usr/sbin中(例如)。但是,当从/etc/rc.local调用时,该目录可能不在$PATH中。您可以在 C 程序中添加这些命令的完整路径。或者,您可以添加(例如):export PATH=/usr/sbin:$PATH到您的 RC 文件中。 -
感谢您的回复。 root@ATK-IMX6U:~# ls -l /etc/rc.local -rwxr-xr-x 1 1000 tracking 497 Mar 18 17:05 /etc/rc.local
-
感谢您的提示。不确定是不是你的意思。 #!/bin/sh -e export PATH=/usr/sbin:$PATH /home/root/can_init >/dev/null 2>&1 & echo "test 2" exit 0 env ... PATH=/usr/local /bin:/usr/bin:/bin:/usr/sbin:/usr/local/sbin:/usr/sbin:/sbin ...但还是不行。
-
与其编辑帖子标题以标记问题已解决,您能否在发布到此问题的答案中简要写下解决方案?与可能是短暂的 cmet 相比,它对未来的读者会更有帮助。