def safe_kill(pid, sig, name):
 if (sig == signal.SIG_DFL):
  try:
   proc_file = ('%s/%d/cmdline' % (PROC_DIR, pid))
   if os.path.exists(proc_file):
    with open(proc_file, 'r') as fd:
     if (name not in fd.read()):
      raise InvalidPidFileException()
  except IOError:
   pass
 os.kill(pid, sig)

def safe_kill ( pid , sig , name ) : if ( sig == signal . SIG_DFL ) : try : proc_file = ( '%s/%d/cmdline' % ( PROC_DIR , pid ) ) if os . path . exists ( proc_file ) : with open ( proc_file , 'r' ) as fd : if ( name not in fd . read ( ) ) : raise InvalidPidFileException ( ) except IOError : pass os . kill ( pid , sig )
send signal to process and check process name : param pid: process id : param sig: signal to send : param name: name to ensure target process .