def find_child_pids(pid, recursive=False):
 try:
  raw_pids = execute(['ps', '--ppid', pid, '-o', 'pid='], log_fail_as_error=False)
 except ProcessExecutionError as e:
  with excutils.save_and_reraise_exception() as ctxt:
   no_children_found = (e.returncode == 1)
   if no_children_found:
    ctxt.reraise = False
    return []
 child_pids = [x.strip() for x in raw_pids.split('\n') if x.strip()]
 if recursive:
  for child in child_pids:
   child_pids = (child_pids + find_child_pids(child, True))
 return child_pids

def find_child_pids ( pid , recursive = False ) : try : raw_pids = execute ( [ 'ps' , '--ppid' , pid , '-o' , 'pid=' ] , log_fail_as_error = False ) except ProcessExecutionError as e : with excutils . save_and_reraise_exception ( ) as ctxt : no_children_found = ( e . returncode == 1 ) if no_children_found : ctxt . reraise = False return [ ] child_pids = [ x . strip ( ) for x in raw_pids . split ( '\n' ) if x . strip ( ) ] if recursive : for child in child_pids : child_pids = ( child_pids + find_child_pids ( child , True ) ) return child_pids
retrieve a list of the pids of child processes of the given pid .