問題
使用python殺死進(jìn)程后自身程序也會(huì)退出,無法執(zhí)行后邊的代碼
這樣不行:文章來源:http://www.zghlxwxcb.cn/news/detail-681099.html
# cmd = " ps -ef | grep -v grep | grep -E 'task_pull_and_submit.py$|upgrade_system.py$'| awk '{print $2}'"
# pids = os.popen(cmd).read().strip('\n').split('\n')
# print(pids)
# for pid in pids:
# os.system("kill -9 {}".format(pid))
解決
使用shell腳本殺死進(jìn)程,然后再讓shell腳本運(yùn)行該python程序
替代方案:文章來源地址http://www.zghlxwxcb.cn/news/detail-681099.html
#!/bin/bash
task_pull_and_submit=`ps -ef | grep -v grep | grep -E 'task_pull_and_submit.py$'| awk '{print $2}'`
if (($task_pull_and_submit));
then
kill -9 $task_pull_and_submit
fi
upgrade_system=`ps -ef | grep -v grep | grep -E 'upgrade_system.py$'| awk '{print $2}'`
if (($upgrade_system));
then
kill -9 $upgrade_system
fi
# 先 cd 到絕對(duì)目錄下執(zhí)行
cd /opt/apps/back_data && nohup python backup_data.py &
到了這里,關(guān)于【python】【centos】使用python殺死進(jìn)程后自身也會(huì)退出的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!