xxfpmFastCGI進(jìn)程管理器
經(jīng)測試,支持Win32和Linux-x86平臺。對于用php的人,有了這個東西來維護(hù)一定數(shù)量的進(jìn)程,就能制服經(jīng)常崩潰退出的php-cgi啦?。?!
Usage: xxfpm path [-n number] [-i ip] [-p port]
Manage FastCGI processes.-n, --number number of processes to keep
-i, --ip ip address to bind
-p, --port port to bind, default is 8000
-u, --user start processes using specified linux user
-g, --group start processes using specified linux group
-r, --root change root direcotry for the processes
-h, --help output usage information and exit
-v, --version output version information and exit
第一個寫得比較標(biāo)準(zhǔn)的終端應(yīng)用程序,我是看了cygwin的里的一些源代碼,然后學(xué)會了如何使用getopt,算是寫得比較標(biāo)準(zhǔn)的,但是代碼也不短。
使用例子:
xxfpm z:/php5/php-cgi.exe -n 5 -p 8080
有人問,如何給程序加入?yún)?shù)?這個不難,使用雙引號即可,路徑要用"/"而不用"\"。例如要指定php.ini的路徑,可以用下面例子:
xxfpm "z:/php5/php-cgi.exe -c z:/php5/php.ini" -n 5 -i 127.0.0.1 -p 8080
如何維護(hù)進(jìn)程:
Windows上使用CreateProcess創(chuàng)建進(jìn)程,使用WaitForSingleObject等待進(jìn)程結(jié)束;Linux上使用fork和 execl創(chuàng)建進(jìn)程,使用waitpid等待進(jìn)程結(jié)束。Linux的版本多了在創(chuàng)建子進(jìn)程的時候可以設(shè)置進(jìn)程限制,能夠以受限用戶方式來運(yùn)行。
當(dāng)進(jìn)程管理器被關(guān)閉的時候,它所創(chuàng)建的所有子進(jìn)程也必須被關(guān)閉。Windows上使用JobObject這個東西來把子進(jìn)程與管理器的進(jìn)程產(chǎn)生關(guān) 聯(lián),感謝iceboy提供的資料!Linux上通過捕捉關(guān)閉信號,然后給所有子進(jìn)程發(fā)送SIGTERM來結(jié)束子進(jìn)程。詳見源代碼?。?!
