关于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个程序都运行了

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值