關於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個程序都運行了

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章