def find_parent_pid(pid):
 try:
  ppid = execute(['ps', '-o', 'ppid=', pid], log_fail_as_error=False)
 except ProcessExecutionError as e:
  with excutils.save_and_reraise_exception() as ctxt:
   no_such_pid = (e.returncode == 1)
   if no_such_pid:
    ctxt.reraise = False
    return
 return ppid.strip()

def find_parent_pid ( pid ) : try : ppid = execute ( [ 'ps' , '-o' , 'ppid=' , pid ] , log_fail_as_error = False ) except ProcessExecutionError as e : with excutils . save_and_reraise_exception ( ) as ctxt : no_such_pid = ( e . returncode == 1 ) if no_such_pid : ctxt . reraise = False return return ppid . strip ( )
retrieve the pid of the parent process of the given pid .