0

I have managed to start a VPN with this code

tunnel_file = "sudo /opt/local/sbin/openvpn2 primary_config.ovpn"

VPNProcess = subprocess.Popen(tunnel_file,shell = True)

The trouble is that I can't stop this process I tried -

VPNProcess.send_signal(signal.SIGINT)

and also sending SIGTERM or SIGKILL but none of them work. Not even VPNProcess.terminate() works. I can list the processes, it seems two are started, a sudo process and an openvpn2 process but if I try killing them in Terminal with kill number I get the response "operation not allowed" Any ideas?

  • Try it with `shell=False`. – Keith Mar 14 '19 at 17:05
  • You can't kill the `sudo` process because it's setuid, and you can't kill the `openvpn2` process because it's running as a different user (root). You probably should create a new pseudoterminal (pty) to run `sudo` in; then you can send Ctrl-C to the pty. – Daniel Pryden Mar 14 '19 at 17:33

0 Answers0