我每次都創建一個進程,但在「kill -9 -1」之後,我失去了創建的進程。我知道我爲什麼每次都丟失它。 但是,無論如何,我可以讓我的程序自動運行,每當我打開電腦時?如何編寫一個程序,每當我打開我的電腦,在Linux中自動運行?
感謝,,
我每次都創建一個進程,但在「kill -9 -1」之後,我失去了創建的進程。我知道我爲什麼每次都丟失它。 但是,無論如何,我可以讓我的程序自動運行,每當我打開電腦時?如何編寫一個程序,每當我打開我的電腦,在Linux中自動運行?
感謝,,
大多數發行版仍然支持SysV Init Scripts。
做到這一點,最簡單的方法就是從/etc/init.d/
採取簡單的init腳本,並更改爲滿足您的需求:
sudo cp /etc/init.d/foo /etc/init.d/my_foo
sudo gedit /etc/init.d/my_foo
然後,你需要啓用它:
sudo /sbin/chkconfig my_foo on
如果chkconfig
不可用,則可能需要安裝它。此外,還有像insserv
這樣的LSB別名可能可用。
Ubuntu系統現在提供Upstart,其配置文件可能比系統V init
腳本少一點冗長。對於暴發戶一個簡單的工作配置是這樣的,而進入,也就是說,/etc/init/example.conf
:
# this is a comment
start on startup
stop on shutdown
exec /path/to/program --some-args maybe-another-arg
然後,它會分別啓動和停止,那麼,在啓動和關機時。要手動啓動和停止它,使用start
和stop
命令爲root
:
$ sudo start example
$ sudo stop example
您可以找到有關its Cookbook新貴配置的詳細信息。有關安裝Upstart的系統的第5部分的手冊頁init
中也提供了相關信息。 (man 5 init
)
Supervisor將讓你這樣做,也有一些其他的功能,如支持FastCGI自動重生的服務,如果他們崩潰的(但是聰明一點,而不是重新啓動它,如果它總是崩潰一遍又一遍)並保留其輸出的日誌。
當它是installed和itself configured to run on startup之後,您可以修改其配置文件以添加運行程序的部分。一個簡單的例子可能是這樣的:
; this is a comment
[program:example]
command = /path/to/program --some-args maybe-another-arg
這是真的那麼有必要用一個簡單的程序,但許多其他配置選項; see the documentation。
一旦你加入你的配置,你可以告訴主管添加/刪除(和啓動/停止)的所有進程您添加或從配置中刪除:
$ sudo supervisorctl update
您可手動啓動如果您想要停止服務,請執行以下操作:
$ sudo supervisorctl start example
$ sudo supervisorctl stop example
$ sudo supervisorctl restart example
您還可以看到所有進程的漂亮狀態顯示,例如:
$ sudo supervisorctl status
cgi-pass RUNNING pid 4223, uptime 68 days, 23:57:22
而且也看到它記錄你的程序的輸出:
$ sudo supervisorctl tail example # stdout
$ sudo supervisorctl tail example stderr # stderr
$ sudo supervisorctl tail -f example # continuous
可用的命令文件可與supervisorctl help
。
Fedora附帶systemd,許多其他的Linux發行版都採用它(除Ubuntu和Debian之外)。該軟件包包含多個幫助程序,您可能需要查看這些程序。
沒有足夠的信息給出一個很好的答案。可能爲您的計算機加載Linux的GRUB或GRUB2引導加載程序可以執行許多操作,但似乎您希望運行的程序具有用戶(您)的權限,這表示基於登錄時的方法。這可能是你的問題是錯誤的論壇。 – hardmath 2013-02-23 14:35:08
http://unix.stackexchange.com上的這個問題不是更好嗎? – 2013-02-24 01:15:59