在工作中,會發現gunicorn啟動的web服務,無論怎么使用kill -9 進程號都是無法殺死gunicorn,經過我一番百度和谷歌,發現想要刪除gunicorn進程其實很簡單。
第一步獲取Gunicorn進程樹:
通過執行如下命令,可以獲取Gunicorn進程樹:
pstree -ap|grep gunicorn
得到的結果如下
Python
| | |-grep,14519 --color=auto gunicorn
| `-gunicorn,28097 /usr/local/bin/gunicorn query_site.wsgi:application -c ...
| |-gunicorn,14226 /usr/local/bin/gunicorn query_site.wsgi:application -c ...
| | |-{gunicorn},14229
| | |-{gunicorn},14230
| | |-{gunicorn},14231
| | |-{gunicorn},14232
| | |-{gunicorn},14233
| | |-{gunicorn},14234
| | |-{gunicorn},14236
| | |-{gunicorn},14237
| | |-{gunicorn},14238
| | |-{gunicorn},14239
| | |-{gunicorn},14240
| | |-{gunicorn},14241
| | |-{gunicorn},14242
| | |-{gunicorn},14243
| | `-{gunicorn},14244
2. 重啟Gunicorn任務
Python
kill -HUP 14226
3. 退出Gunicorn任務
Python
kill -9 28097
執行上述命令后,再次執行“pstree -ap|grep gunicorn”,我們很容易發現,除了主進程,其他的Gunicorn進程都已經銷毀,並新建了進程(進程ID發生了變化)。