微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么以及如何从 /etc/rc.local 运行系统进程?

如何解决为什么以及如何从 /etc/rc.local 运行系统进程?

我无法从 /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

解决方法

问题已解决,

正如 Craig Estey 所说,通过包含 /etc/rc.local 的 /sbin 路径,应用程序成功执行了 ifconfig、ip 和 ismod 命令


#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each#!/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
source /etc/profile
export PATH=/sbin:$PATH
/home/root/can_init >/dev/null 2>&1 &
echo "test 2"
exit 0
/* from can_init.c */ 

status = system("/usr/sbin/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");

    status = system("insmod /home/root/mx6s_capture.ko");

重启后,应用程序执行can配置:

Running local boot scripts (/etc/rc.local)test 2
.
[    9.635097] flexcan 2090000.can can0: writing ctrl=0x0bff2002

[   13.566306] CSI: Registered sensor subdevice: ov5640 1-0021
^C
root@ATK-IMX6U:~# ip -details link show can0
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 100
          bitrate 125000 sample-point 0.600
          tq 400 prop-seg 3 phase-seg1 8 phase-seg2 8 sjw 4
          flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1
          clock 30000000

root@ATK-IMX6U:~# lsmod
Module                  Size  Used by
mx6s_capture           14876  0

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。