当前位置: 首页>>代码示例>>Python>>正文


Python psutil.pids方法代码示例

本文整理汇总了Python中psutil.pids方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.pids方法的具体用法?Python psutil.pids怎么用?Python psutil.pids使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psutil的用法示例。


在下文中一共展示了psutil.pids方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_issue_687

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def test_issue_687(self):
        # In case of thread ID:
        # - pid_exists() is supposed to return False
        # - Process(tid) is supposed to work
        # - pids() should not return the TID
        # See: https://github.com/giampaolo/psutil/issues/687
        t = ThreadTask()
        t.start()
        try:
            p = psutil.Process()
            tid = p.threads()[1].id
            assert not psutil.pid_exists(tid), tid
            pt = psutil.Process(tid)
            pt.as_dict()
            self.assertNotIn(tid, psutil.pids())
        finally:
            t.stop() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_linux.py

示例2: test_exe_mocked

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def test_exe_mocked(self):
        with mock.patch('psutil._pslinux.readlink',
                        side_effect=OSError(errno.ENOENT, "")) as m1:
            with mock.patch('psutil.Process.cmdline',
                            side_effect=psutil.AccessDenied(0, "")) as m2:
                # No such file error; might be raised also if /proc/pid/exe
                # path actually exists for system processes with low pids
                # (about 0-20). In this case psutil is supposed to return
                # an empty string.
                ret = psutil.Process().exe()
                assert m1.called
                assert m2.called
                self.assertEqual(ret, "")

                # ...but if /proc/pid no longer exist we're supposed to treat
                # it as an alias for zombie process
                with mock.patch('psutil._pslinux.os.path.lexists',
                                return_value=False):
                    self.assertRaises(
                        psutil.ZombieProcess, psutil.Process().exe) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:test_linux.py

示例3: test_pids

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def test_pids(self):
        # Note: this test might fail if the OS is starting/killing
        # other processes in the meantime
        pids_ps = sorted(ps("pid"))
        pids_psutil = psutil.pids()

        # on MACOS and OPENBSD ps doesn't show pid 0
        if MACOS or OPENBSD and 0 not in pids_ps:
            pids_ps.insert(0, 0)

        # There will often be one more process in pids_ps for ps itself
        if len(pids_ps) - len(pids_psutil) > 1:
            difference = [x for x in pids_psutil if x not in pids_ps] + \
                         [x for x in pids_ps if x not in pids_psutil]
            self.fail("difference: " + str(difference))

    # for some reason ifconfig -a does not report all interfaces
    # returned by psutil 
开发者ID:giampaolo,项目名称:psutil,代码行数:20,代码来源:test_posix.py

示例4: test_issue_687

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def test_issue_687(self):
        # In case of thread ID:
        # - pid_exists() is supposed to return False
        # - Process(tid) is supposed to work
        # - pids() should not return the TID
        # See: https://github.com/giampaolo/psutil/issues/687
        t = ThreadTask()
        t.start()
        try:
            p = psutil.Process()
            threads = p.threads()
            self.assertEqual(len(threads), 2)
            tid = sorted(threads, key=lambda x: x.id)[1].id
            self.assertNotEqual(p.pid, tid)
            pt = psutil.Process(tid)
            pt.as_dict()
            self.assertNotIn(tid, psutil.pids())
        finally:
            t.stop() 
开发者ID:giampaolo,项目名称:psutil,代码行数:21,代码来源:test_linux.py

示例5: pidmonitor

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def pidmonitor():
    processes = ['streamparse.run', 'java']
    for pid in psutil.pids():
        proc = psutil.Process(pid)
        for process in processes:
            if process in proc.cmdline():
                cmdline = proc.cmdline()
                main_proc = cmdline[0]
                details = []
                if main_proc == 'java':
                    details.append('[storm]')
                elif main_proc == 'python':
                    details.extend(cmdline[2:4])
                    for detail in details:
                        if 'Spout' in detail:
                            details.append('[spout]')
                        if 'Bolt' in detail:
                            details.append('[bolt]')
                print(main_proc, ' '.join(details))
                print('=> CPU% {}'.format(proc.cpu_percent(interval = 0.2))) 
开发者ID:huseinzol05,项目名称:Gather-Deployment,代码行数:22,代码来源:ps.py

示例6: test___init__no_params

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def test___init__no_params(self):
        # if  backplane is not running, start one for all the tests
        for pid in psutil.pids():
            p = psutil.Process(pid)
            if p.name() == "backplane":
                break
            else:
                self.proc = Popen(['backplane'],
                                  stdin=subprocess.PIPE, stderr=subprocess.PIPE,
                                  stdout=subprocess.PIPE)
                break

        b = BanyanBase()
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        # use the google dns
        try:
            s.connect(('8.8.8.8', 1))
            back_plane_ip_address = s.getsockname()[0]
        except:
            back_plane_ip_address = '127.0.0.1'
        finally:
            s.close()

        b.clean_up()
        assert b.back_plane_ip_address == back_plane_ip_address 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:27,代码来源:test_banyanBase.py

示例7: get_processes

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def get_processes(self):
        for p in pids():
            try:
                pr = Process(p)
                path = pr.exe()
                name = pr.name()
                file_open = open(path, 'rb')
                read = file_open.read()
                arch = "?? bits"
                if b"PE\0\0L" in read:
                    arch = "32 bits"
                elif b"PE\0\0d" in  read:
                    arch = "64 bits"
                print(name +"(" + str(p) + "): " + arch)
                file_open.close()
            except:
                pass 
开发者ID:Josue87,项目名称:BoomER,代码行数:19,代码来源:dll_injection.py

示例8: GetProcessByName

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def GetProcessByName(self, name):
        processlist = []
        # At python.psutil 2.0.0, psutil.get_pid_list() has been replaced
        # by psutil.pids(). Try to access the new one first,
        # If that throws, try the old one.

        try:
            pids = psutil.pids()
        except:
            pids = psutil.get_pid_list()

        for pid in pids:
            try:
                p = psutil.Process(pid)
                if p.name == name:
                    processlist.append(p)
            except:
                pass
        return processlist 
开发者ID:openweave,项目名称:happy,代码行数:21,代码来源:HappyProcess.py

示例9: pids

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def pids() -> Iterable[ProcessId]:
        _PROC_ID_T = DWORD
        list_size = 4096

        def try_get_pids(list_size: int) -> List[ProcessId]:
            result_size = DWORD()
            proc_id_list = (_PROC_ID_T * list_size)()

            if not windll.psapi.EnumProcesses(byref(proc_id_list), sizeof(proc_id_list), byref(result_size)):
                raise WinError(descr="Failed to get process ID list: %s" % FormatError())  # type: ignore

            return cast(List[ProcessId], proc_id_list[:int(result_size.value / sizeof(_PROC_ID_T()))])

        while True:
            proc_ids = try_get_pids(list_size)
            if len(proc_ids) < list_size:
                return proc_ids

            list_size *= 2 
开发者ID:TouwaStar,项目名称:Galaxy_Plugin_Bethesda,代码行数:21,代码来源:proc_tools.py

示例10: run_module

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def run_module(self):
        # To access user provided attributes, use self.options dictionary

        Thread(target=self.monitoring).start()

        print "\n[*] STARTING PROGRAMS EXECUTION IN 5 SECONDS...\n"
        time.sleep(5)

        for b in self.binaries():
            self.print_info("  [+] Executing %s ..." % b)
            previous_pid = psutil.pids()
            self.execute(b)
            time.sleep(int(self.args["sleep_time"]))
            new_pid = psutil.pids()
            print "  [-] Killing the process"
            self.kill(b.split('.')[0], previous_pid, new_pid)

        print "\n[*] PLEASE CLOSE PROCMON PROCESS\n"
        self.parsing_results()
        print "\n[*] RESULTS PARSED TO XML\n" 
开发者ID:ElevenPaths,项目名称:uac-a-mola,代码行数:22,代码来源:procmon.py

示例11: check_services

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def check_services(service_name):
    """
    check to see if certain services ar started
    """
    try:
        all_processes = set()
        for pid in psutil.pids():
            running_proc = psutil.Process(pid)
            all_processes.add(" ".join(running_proc.cmdline()).strip())
        for proc in list(all_processes):
            if service_name in proc:
                return True
        return False
    except psutil.ZombieProcess as e:
        # zombie processes appear to happen on macOS for some reason
        # so we'll just kill them off
        pid = str(e).split("=")[-1].split(")")[0]
        os.kill(int(pid), 0)
        return True 
开发者ID:NullArray,项目名称:AutoSploit,代码行数:21,代码来源:settings.py

示例12: is_running

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def is_running(program, argument):
    # iterate over all process id's found by psutil
    for pid in psutil.pids():
        try:
            # requests the process information corresponding to each process id
            p = psutil.Process(pid)
            # check if value of program-variable that was used to call the function matches the name field of the plutil.Process(pid) output 
            if program in p.name():
                # check output of p.name(), output name of program
                # p.cmdline() - echo the exact command line via which p was called.
                for arg in p.cmdline():
                    if argument in str(arg):  
                        return True
                    else:
                        pass
            else:
                pass
        except:
            continue

# check if auto-cpufreq --daemon is running 
开发者ID:AdnanHodzic,项目名称:auto-cpufreq,代码行数:23,代码来源:core.py

示例13: kill_all

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def kill_all():
    """Kill ALL of the running vcsim pids"""

    results = []

    for x in psutil.pids():
        p = psutil.Process(x)
        if VCSIMPATH in p.cmdline():
            success = False
            e = None
            try:
                p.terminate()
                success = True
            except Exception as e:
                pass
            results.append(
                {'pid': x, 'cmdline': p.cmdline(),
                 'success': success, 'e': str(e)}
            )

    return jsonify(results) 
开发者ID:ansible,项目名称:vcenter-test-container,代码行数:23,代码来源:flask_control.py

示例14: POST

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def POST(self):
        cpuused = psutil.cpu_percent(interval=None, percpu=False)
        memused = psutil.virtual_memory()[2]
        diskused = psutil.disk_usage('/')[3]
        pidcount = len(psutil.pids())

        uptimeshell = subprocess.Popen(['uptime'], stderr=subprocess.PIPE,stdout=subprocess.PIPE)
        uptimeshell.wait()
        uptime = uptimeshell.communicate()

        return json.dumps(
            {
                "code": 0,
                "current": {
                    "cpuused": cpuused,
                    "memused": memused,
                    "diskused": diskused,
                    "pidcount": pidcount,
                    "uptime": uptime
                }
            }
        ) 
开发者ID:kbdancer,项目名称:WIFIHTTPMonitor,代码行数:24,代码来源:monitor.py

示例15: do_check_process_is_dead

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import pids [as 别名]
def do_check_process_is_dead():
    """执行检测ui_progress_dict中的进程pid是否仍然活着,如果死了,从字典中清除,close ui"""
    import psutil
    # 获取活着的所有pid序列
    living = psutil.pids()
    clear_arr = list()
    for progress_pid in ui_progress_dict:
        # 需要临时转换一次int,living中进程序列是int
        if int(progress_pid) not in living:
            # 字典中记录的pid如果不在活着的序列中,清除
            clear_arr.append(progress_pid)
    for clear_pid in clear_arr:
        if clear_pid in ui_progress_dict:
            pop_progress = ui_progress_dict.pop(clear_pid, None)
            if pop_progress is not None:
                pop_progress.close()


# 不管ui进度条有什么问题,也不能影响任务主进程主任务工作的进度执行 
开发者ID:bbfamily,项目名称:abu,代码行数:21,代码来源:ABuProgress.py


注:本文中的psutil.pids方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。