def killall(name, signum, group=False): exception = _NO_ERROR knownPgs = set() pidList = proc.pgrep(name) if len(pidList) == 0: raise OSError(errno.ESRCH, "Could not find processes named `%s`" % name) for pid in pidList: try: if group: pgid = os.getpgid(pid) if pgid in knownPgs: # Signal already sent, ignore continue knownPgs.add(pgid) os.killpg(pgid, signum) else: os.kill(pid, signum) except OSError as e: if e.errno == errno.ESRCH: # process died in the interim, ignore continue exception = e if exception is not _NO_ERROR: raise exception
def killall(name, signum, group=False): exception = _NO_ERROR knownPgs = set() pidList = proc.pgrep(name) if len(pidList) == 0: raise OSError(errno.ESRCH, "Could not find processes named `%s`" % name) for pid in pidList: try: if group: pgid = os.getpgid(pid) if pgid in knownPgs: # Signal already sent, ignore continue knownPgs.add(pgid) os.killpg(pgid, signum) else: os.kill(pid, signum) except OSError as e: if e.errno == errno.ESRCH: # process died in the interim, ignore continue exception = e if exception is not _NO_ERROR: raise exception
def dhcp_info(devices): info = {devname: {DHCP4: False, DHCP6: False} for devname in devices} for pid in pgrep('dhclient'): args = _read_cmdline(pid) if not args: continue dev = args[-1] if dev not in info: continue dhcp_version_key = DHCP6 if '-6' in args[:-1] else DHCP4 info[dev][dhcp_version_key] = True return info
def dhcp_info(devices): info = {devname: {DHCP4: False, DHCP6: False} for devname in devices} for pid in pgrep('dhclient'): args = _read_cmdline(pid) if not args: continue dev = args[-1] if dev not in info: continue dhcp_version_key = DHCP6 if '-6' in args[:-1] else DHCP4 info[dev][dhcp_version_key] = True return info
def test(self): sleepProcs = [] try: for i in range(3): popen = Popen([EXT_SLEEP, "3"]) sleepProcs.append(popen) # There is no guarantee which process run first after forking a # child process, make sure all the children are runing before we # look for them. time.sleep(0.5) pids = proc.pgrep(EXT_SLEEP) for popen in sleepProcs: self.assertIn(popen.pid, pids) finally: for popen in sleepProcs: popen.kill() popen.wait()
def _pid_lookup(device_name, family): for pid in pgrep('dhclient'): args = _read_cmdline(pid) if not args: continue if args[-1] != device_name: # dhclient of another device continue tokens = iter(args) pid_file = '/var/run/dhclient.pid' # Default client pid location running_family = 4 for token in tokens: if token == '-pf': pid_file = next(tokens) elif token == '--no-pid': pid_file = None elif token == '-6': running_family = 6 if running_family != family: continue yield pid, pid_file
def _pid_lookup(device_name, family): for pid in pgrep('dhclient'): args = _read_cmdline(pid) if not args: continue if args[-1] != device_name: # dhclient of another device continue tokens = iter(args) pid_file = '/var/run/dhclient.pid' # Default client pid location running_family = 4 for token in tokens: if token == '-pf': pid_file = next(tokens) elif token == '--no-pid': pid_file = None elif token == '-6': running_family = 6 if running_family != family: continue yield pid, pid_file
def _nm_is_running(): return len(pgrep('NetworkManager')) > 0
def _get_dhclient_ifaces(): pids = pgrep('dhclient') return [ open('/proc/%s/cmdline' % pid).read().strip('\0').split('\0')[-1] for pid in pids ]
def _nm_is_running(): return len(pgrep('NetworkManager')) > 0