关于rc.local 自启动多个应用问题

有2个C生成的文件,需要在开机的时候启动。

按如下方式添加,只能启动第一个

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

./etc/nnn1

./etc/nnn2

exit 0

然后修改成如下,也是只能启动前面一个

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

cd /etc

./nnn1

cd /etc

./nnn2

exit 0

多次对比测试,发现,这两个程序都是涉及到通信,不返还的,就是不终止程序,一旦启动就一直在运行,相当于不能退出了,所以后面的语句就无法执行了

于是采用了如下方式:

int main(void)
 {
         int i;
        if ( fork() == 0 )
         {
         /* 子进程程序 */
                    system("cd /etc");
                     system("./nnn1");

          }
         else
        {
            system("cd /etc");
             system("./nnn2");

         }
}

相当于多线程运行,然后生成了一个运行文件,nnn3,在rc.loacl中添加如下:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

chmod 777 /etc/nnn3
cd /etc
./nnn3

exit 0

开机可以同时2个程序都运行了

发布了47 篇原创文章 · 获赞 28 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/x13163303344/article/details/89390144