/********************************************************************** * Linux 進程退出后自動啟動 * 說明: * 在系統中,我們有時候會希望后台程序能夠一直運行,即使程序出錯了, * 也是希望程序能夠自動啟動,並繼續運行。 * * 2016-12-10 深圳 南山平山村 曾劍鋒 *********************************************************************/ 一、參考文檔: How to automatically restart a linux background process if it fails? http://superuser.com/questions/507576/how-to-automatically-restart-a-linux-background-process-if-it-fails 二、解決辦法: 1. 如參考文檔中的說明,分三種情況: 1. BusyBox init:在/etc/inittab中添加: ::respawn:/bin/myprocess 2. Linux "System V" init:在/etc/inittab中添加: myprocess:2345:respawn:/bin/myprocess 3. systemd: 1. 在/etc/systemd/system/myprocess.service中添加: [Unit] Description=My Process [Service] ExecStart=/bin/myprocess Restart=always [Install] WantedBy=multi-user.target 2. systemctl enable myprocess.service 2. 詳情請參考: http://buildroot.uclibc.org/downloads/manual/manual.html#_init_system 3. systemctl start myprocess.service