示例#1
0
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
示例#2
0
文件: misc.py 项目: nirs/vdsm
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
示例#3
0
文件: dhclient.py 项目: EdDev/vdsm
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
示例#4
0
文件: dhclient.py 项目: akashihi/vdsm
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
示例#5
0
 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()
示例#6
0
文件: dhclient.py 项目: EdDev/vdsm
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
示例#7
0
文件: dhclient.py 项目: akashihi/vdsm
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
示例#8
0
def _nm_is_running():
    return len(pgrep('NetworkManager')) > 0
示例#9
0
 def _get_dhclient_ifaces():
     pids = pgrep('dhclient')
     return [
         open('/proc/%s/cmdline' %
              pid).read().strip('\0').split('\0')[-1] for pid in pids
     ]
示例#10
0
文件: nettestlib.py 项目: oVirt/vdsm
def _nm_is_running():
    return len(pgrep('NetworkManager')) > 0