📌  相关文章
📜  如何使用 python 代码示例检查任何脚本是否在后台 linux 中运行

📅  最后修改于: 2022-03-11 14:45:20.181000             🧑  作者: Mango

代码示例1
def check_process():
    import subprocess
    script_name = "test.py"
    cmd='pgrep -f .*python.*{}'.format(script_name)
    process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    my_pid, err = process.communicate()
    if len(my_pid.splitlines()) >0:
        print("Script Running in background")
        sys.exit(0);
check_process()