def terminate_root_and_child_processes(root_pid): """Terminate the root process along with any children it spawned.""" app_name = environment.get_value('APP_NAME') direct_children = utils.get_process_ids(root_pid, recursive=False) for child_pid in direct_children: # utils.get_process_ids also returns the parent pid. if child_pid == root_pid: continue try: child = psutil.Process(child_pid) except Exception: # Process doesn't exist anymore. continue if child.name() == app_name: # Send SIGTERM to the root APP_NAME process only, and none of its children # so that coverage data will be dumped properly (e.g. the browser process # of chrome). # TODO(ochang): Figure out how windows coverage is dumped since there is # no equivalent of SIGTERM. terminate_process(child_pid, kill=False) continue child_and_grand_children_pids = utils.get_process_ids(child_pid, recursive=True) for pid in child_and_grand_children_pids: terminate_process(pid, kill=True) terminate_process(root_pid, kill=True)
def find_windows_for_process(process_id): """Return visible windows belonging to a process.""" pids = utils.get_process_ids(process_id) if not pids: return [] visible_windows = [] for pid in pids: app = application.Application() try: app.connect(process=pid) except: logs.log_warn('Unable to connect to process.') continue try: windows = app.windows() except: logs.log_warn('Unable to get application windows.') continue for window in windows: try: window.type_keys('') except: continue visible_windows.append(window) return visible_windows
def find_windows_for_process(process_id): """Return visible windows belonging to a process.""" pids = utils.get_process_ids(process_id) if not pids: return [] xdotool_path = _xdotool_path() if not xdotool_path: logs.log_error('Xdotool not installed, cannot locate process windows.') return [] visible_windows = [] for pid in pids: windows = (shell.execute_command( '%s search --all --pid %d --onlyvisible' % (xdotool_path, pid))) for line in windows.splitlines(): if not line.isdigit(): continue visible_windows.append(int(line)) return visible_windows