Best Python code snippet using avocado_python
process.py
Source:process.py  
...154    """155    with open('/proc/%d/stat' % pid, 'rb') as proc_stat:156        parent_pid = proc_stat.read().split(b' ')[-49]157        return int(parent_pid)158def _get_pid_from_proc_pid_stat(proc_path):159    match = re.match(r'\/proc\/([0-9]+)\/.*', proc_path)160    if match is not None:161        return int(match.group(1))162def get_children_pids(parent_pid, recursive=False):163    """164    Returns the children PIDs for the given process165    :note: This is currently Linux specific.166    :param parent_pid: The PID of parent child process167    :returns: The PIDs for the children processes168    :rtype: list of int169    """170    proc_stats = glob.glob('/proc/[123456789]*/stat')171    children = []172    for proc_stat in proc_stats:173        try:174            with open(proc_stat, 'rb') as proc_stat_fp:175                this_parent_pid = int(proc_stat_fp.read().split(b' ')[-49])176        except IOError:177            continue178        if this_parent_pid == parent_pid:179            children.append(_get_pid_from_proc_pid_stat(proc_stat))180    if recursive:181        for child in children:182            children.extend(get_children_pids(child))183    return children184def kill_process_tree(pid, sig=None, send_sigcont=True, timeout=0):185    """186    Signal a process and all of its children.187    If the process does not exist -- return.188    :param pid: The pid of the process to signal.189    :param sig: The signal to send to the processes, defaults to190                :data:`signal.SIGKILL`191    :param send_sigcont: Send SIGCONT to allow killing stopped processes192    :param timeout: How long to wait for the pid(s) to die193                    (negative=infinity, 0=don't wait,...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
