import psutil import json def getpid(): reslut = psutil.pids() return reslut def getpidname(): reslut = {} pids = getpid() for pid in pids: pidname = psutil.Process(pid) reslut[pid] = pidname.name() return json.dumps(reslut,indent=4) print getpidname()
结果:
{ "1": "init", "2": "kthreadd", "3": "migration/0", "4": "ksoftirqd/0", "5": "stopper/0", "6": "watchdog/0", "7": "migration/1", "8": "stopper/1", "9": "ksoftirqd/1", "10": "watchdog/1", "11": "events/0", "12": "events/1", "13": "events/0", "14": "events/1", "15": "events_long/0", "16": "events_long/1", "17": "events_power_ef", "18": "events_power_ef", "19": "cgroup", "20": "khelper", "21": "netns", "22": "async/mgr", "23": "pm", "24": "sync_supers", "25": "bdi-default", "26": "kintegrityd/0", "27": "kintegrityd/1", "28": "kblockd/0", "29": "kblockd/1", "30": "kacpid", "31": "kacpi_notify", "32": "kacpi_hotplug", "33": "ata_aux", "34": "ata_sff/0", "35": "ata_sff/1", "36": "ksuspend_usbd", "37": "khubd", "38": "kseriod", "39": "md/0", "40": "md/1", "41": "md_misc/0", "42": "md_misc/1", "43": "linkwatch", "45": "khungtaskd", "46": "kswapd0", "47": "ksmd", "48": "khugepaged", "49": "aio/0", "50": "aio/1", "51": "crypto/0", "52": "crypto/1", "59": "kthrotld/0", "60": "kthrotld/1", "61": "pciehpd", "63": "kpsmoused", "64": "usbhid_resumer", "65": "deferwq", "1119": "rsyslogd", "97": "kdmremove", "98": "kstriped", "1139": "sshd", "1173": "mysqld_safe", "187": "scsi_eh_0", "188": "scsi_eh_1", "193": "mpt_poll_0", "194": "mpt/0", "195": "scsi_eh_2", "752": "bluetooth", "803": "jbd2/sda1-8", "804": "ext4-dio-unwrit", "562": "vmmemctl", "323": "jbd2/sda3-8", "324": "ext4-dio-unwrit", "846": "kauditd", "1377": "mysqld", "1438": "crond", "421": "udevd", "1451": "mingetty", "1453": "mingetty", "1455": "mingetty", "1458": "udevd", "1459": "udevd", "1460": "mingetty", "1462": "mingetty", "1464": "mingetty", "1465": "sshd", "1467": "bash", "1514": "flush-8:0", "1517": "python" }
时间: 2024-10-17 20:48:35