English 中文(简体)
当父母用假药被系统阻断时,便离开
原标题:Subproccess exits when parent python script stopped by systemd

我是新来的,希望了解情况,因此,我制作了一幅长篇的文字,从分处理到执行双面文字。 书目为框架设计了环境,并实施了一套可操作的++方案。

打算使用的是,将假装作为监督C++进程的一种服务,如果C++工艺的出走,则将双管开动。

如果我从指挥线(<>条码/proc_watchdog.py)开始使用纸面文字,那么“滚动”就会继续运行。

如果我随后使用系统格式(系统开字典>)执行字典。 服务,C++方案退出。

履历:

[Unit]
Description=RustDedicated watchdog service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=scriptuser
ExecStart=/path/to/C++_Prog_Dir/proc_watchdog.py

[Install]
WantedBy=multi-user.target

The python script:

#!/usr/bin/python3

import subprocess as sp
import os
import psutil
import time

backgroundProc = "Procname"

def processWatchdog():
   waitCount = 0;

   while True:
      procList = []

      for proc in psutil.process_iter():
         procList.append(proc.as_dict(attrs=[ name ]))

      found = 0
      for pname in procList:
         if backgroundProc == pname[ name ]:
            print("Process running")
            found = 1

      if found == 0:
         print("Process not found...")
         waitCount += 1
         if waitCount == 3:
            p = sp.Popen(["/path/to/C++_Prog_Dir/start.sh"])
            print("Restarting")
            p.wait()
            waitCount = 0
            print("Restarted")

      time.sleep(2)

if __name__ ==  __main__ :
   processWatchdog()

Bash 写法:

#!/bin/bash

./c++_process &>> /dev/null &

exit 0

谁能帮助我理解,为什么要用哪一种方式来对待假装?

问题回答

父母是否适当等待孩子。 当儿童离开时,重新开始。 这就是DJB的贱民。

改写:

./c++_process &>> /dev/null &

:

exec ./c++_process &>> /dev/null

Then your watch dog will be alerted immediately when p.wait() returns that it has to restart the program as it had exited. With that your watch dog can be reduced :

import subprocess as sp
import time

def processWatchdog():

   while True:
       p = sp.Popen(["/path/to/C++_Prog_Dir/start.sh"])
       p.wait()

       time.sleep(2)

if __name__ ==  __main__ :
   processWatchdog()

只是重新启动该方案,第二次推迟。

服务参数“KillMode”违约值是“中间集团”,这意味着该单位控制组的所有剩余过程都将被杀死。

“加工”或“无”一使用并运转良好





相关问题
Strip final 0 off a python string

#!/usr/bin/env python import os, sys, subprocess, time while True: print subprocess.call("xsel", shell=True); time.sleep(1); Takes an entry from the clipboard and prints it, every 1 ...

Python popen wont work with block devices

I am wring a small forensic app which looks like this so far import time, os,sys def getter(): filename = sys.argv[1] print "File Entered: " + filename os.system( file + filename) ...

Kill Windows asynchronous Popen process in 2.4

I have a testing script that needs to open a process (a Pyro server), do some stuff that will call the opened process for information, and when it s all done will need to close the process back down. ...

Launching default application for given type of file, OS X

I m writing a python script that generates html file. Every time I run this script I d like at the end to open default system browser for this file. It s all in OS X environment. What python code can ...

Piping Cygwin into a Python program

As a i m new to the whole Piping thing and Python I had recently encountered a problem trying to pipe Cygwin s stdin & stdout into a python program usin Python s subprocess moudle. for example I ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?