parameters: (ppid)
return_statement: return accepted
docstring: Select all processes which are descendant from ppid (exclusive).
docstring_summary: Select all processes which are descendant from ppid (exclusive).
docstring_tokens: Select all processes which are descendant from ppid ( exclusive ) .
function: def get_children(ppid):
      """ Select all processes which are descendant from ppid (exclusive). """
  
      pid_dct = {}
      for proc in build_process_list():
          proc["_children"] = []
          pid_dct[proc["pid"]] = proc
  
      # fill in children array
      for pid in list(pid_dct.keys()):
          parent_pid = pid_dct[pid]["parent_pid"]
  
          if parent_pid in pid_dct:
              pid_dct[parent_pid]["_children"].append(pid)
  
      # now just walk down the tree
      if ppid is None or ppid not in pid_dct:
          # process has quit, we exit
          return []
  
      accepted = []
      to_accept = collections.deque([ppid, ])
      
      while to_accept:
          head = pid_dct[to_accept.popleft()]
  
          # do not include the monitoring pid
          if head["pid"] != ppid:
              accepted.append(head)
  
          to_accept.extend(head.get("_children", []))
          head["children"] = head["_children"]
          del head["_children"]
  
          # deleting children breaks infinite loops
          # but Dima, can a process tree contain a loop? yes - via race-condition in reading procfs
  
      return accepted
function_tokens: def get_children ( ppid ) : pid_dct = { } for proc in build_process_list ( ) : proc [ "_children" ] = [ ] pid_dct [ proc [ "pid" ] ] = proc # fill in children array for pid in list ( pid_dct . keys ( ) ) : parent_pid = pid_dct [ pid ] [ "parent_pid" ] if parent_pid in pid_dct : pid_dct [ parent_pid ] [ "_children" ] . append ( pid ) # now just walk down the tree if ppid is None or ppid not in pid_dct : # process has quit, we exit return [ ] accepted = [ ] to_accept = collections . deque ( [ ppid , ] ) while to_accept : head = pid_dct [ to_accept . popleft ( ) ] # do not include the monitoring pid if head [ "pid" ] != ppid : accepted . append ( head ) to_accept . extend ( head . get ( "_children" , [ ] ) ) head [ "children" ] = head [ "_children" ] del head [ "_children" ] # deleting children breaks infinite loops # but Dima, can a process tree contain a loop? yes - via race-condition in reading procfs return accepted