Last active
March 19, 2016 09:35
-
-
Save skt041959/342c940384f39a4e62b1 to your computer and use it in GitHub Desktop.
start with python, and maintain the processes under python process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
from ctypes import CDLL | |
import subprocess | |
import os | |
import psutil | |
from time import sleep | |
import signal | |
libc = CDLL("libc.so.6") | |
prctl = libc.prctl | |
prctl(36, 1) | |
# WINEPREFIX = "/home/skt/downloads/QQLite" | |
WINEPREFIX = "/home/skt/.longene/qqintl" | |
os.chdir(os.path.join(WINEPREFIX, "drive_c/Program Files/Tencent/QQ2009/Bin/")) | |
os.putenv("WINEPREFIX", WINEPREFIX) | |
os.putenv("WINEDEBUG", "-all") | |
pid = os.getpid() | |
subprocess.Popen(["wine", "QQ.exe"]) | |
def exit_qq(signum, frame): | |
p = psutil.Process(pid) | |
children = p.children() | |
for cp in children: | |
if cp.status() == 'zombie': | |
os.waitpid(cp.pid, os.WNOHANG) | |
else: | |
cp.kill() | |
signal.signal(signal.SIGTERM, exit_qq) | |
signal.signal(signal.SIGINT, exit_qq) | |
def garbege_zombir(pid): | |
p = psutil.Process(pid) | |
children = p.children() | |
for cp in children: | |
if cp.status() == 'zombie': | |
os.waitpid(cp.pid, os.WNOHANG) | |
children = p.children() | |
return len(children) > 0 | |
while 1: | |
sleep(10) | |
if not garbege_zombir(pid): | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment