''' To kill the process: ps -ef | grep python ''' from os import path as _pth from time import sleep CURRENT_DIR = _pth.abspath(_pth.dirname(__file__)) XRAY_PATH = _pth.join(CURRENT_DIR, "config", "xray") def run(): import os, xray_config, subprocess, signal os.chdir(xray_config.CONFIG_DIR) sleep(0.5) p = subprocess.Popen([XRAY_PATH, "-c", xray_config.CONFIG_FILE]) signal.signal(signal.SIGTERM, lambda a, b: p.send_signal(signal.SIGTERM)) try: p.wait() except: p.send_signal(signal.SIGTERM) if __name__ == "__main__": run()