python - Killing process on Ubuntu with os.system() issue -
i try send command python shell ubuntu os
define process existed on particular port , kill it:
port = 8000 os.system("netstat -lpn | grep %s" % port)
output:
tcp 0 0 127.0.0.1.8000 0.0.0.0:* listen 22000/python
then:
os.system("kill -sigterm 22000")
but got following trace
sh: 1: kill: illegal option -s
for reason command can not transferred os full signal -sigterm
, -s
. can kill process directly terminal
, seems it's python
or os
issue... how can run kill
command using python? appreciated
you try using
import signal os.kill(process.pid, signal.sigkill)
documentation can found here.
you use signal.ctrl_c_event
, corresponds ctrl+c keystroke event.
Comments
Post a Comment