1

I want to use mitmproxy to capture my emulator's flow. My idea is using

proc = subprocess.Poen('mitmproxy -T -w emulator.log', shell=True) to start mitmproxy as a parallel process and using kill pid to stop mitmproxy.

But prco.pid shows thay prco is a new shell, mitmproxy is subprocess of proc.

os.killpg(pid, signal.SIGKILL) can't kill process in diffferent shell;

os.getpid get current shell's pid;

subprocess.Popen(str('kill ',proc.pid), shell=True) can't kill mitmproxy.

So, how can I kill mitmproxy which was called python script? Or other method to capture my emulator's flow by mitmproxy.

wuyuanyi
  • 339
  • 1
  • 2
  • 8
  • usually i passed args like 'killall mitmproxy', but not pythonic way ofcourse – noise Feb 18 '16 at 12:46
  • umh, I need to run lots of emulator and each emulator need one mitmproxy, so it does not suit for me. – wuyuanyi Feb 18 '16 at 12:48
  • 1- don't use `shell=True`, call `.split()` on the command and call `proc.terminate()` to kill `mitmproxy` process (it works if mitmproxy kills its descendants on SIGTERM) 2- pass `preexec_fn=os.setpgrp` if you want to use `os.killpg(proc.pid, SIGINT)` later (like Ctrl + C in shell) as described in the duplicate question. – jfs Feb 19 '16 at 13:01

0 Answers0