The method by which python kills the corresponding process according to pid

  • 2020-05-19 05:12:35
  • OfStack

Using the python language to kill the corresponding process according to pid

The kill_process.py code is as follows


#! /usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
import signal


def kill(pid):

  try:
    a = os.kill(pid, signal.SIGKILL)
    # a = os.kill(pid, signal.9) # With the equivalent 
    print ' Has killed pid for %s The process of , The return value is :%s' % (pid, a)
  except OSError, e:
    print ' There is no such process !!!'

if __name__ == '__main__':
  kill(8132)

ok, Enjoy it !!!


Related articles: