日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 系统进程_在Python中监视所有系统进程

發(fā)布時間:2025/4/5 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 系统进程_在Python中监视所有系统进程 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我試圖用Python在我的操作系統(tǒng)(Ubuntu)中收集一些進程的統(tǒng)計信息(生命周期、開始時間/結束時間等)

其中一個任務:我編寫了一個函數(shù),它獲取系統(tǒng)中進程的名稱和ID,但它很難看。在def get_processes():

p = subprocess.Popen(['ps', '-e'], stdout=subprocess.PIPE)

raw_string, e = p.communicate()

strings_arr = raw_string.split('\n')

strings_arr = strings_arr[1:]

processes_dict = {}

# Example of ps -e ansewer: 7 ? 00:00:00 watchdog/0

for string in strings_arr:

splted = string.split()

key, value = None, None

if len(splted) == 0: continue

for item in splted:#looking for process id

if item.isdigit():

key = int(item)

break

value = splted[-1] # looking for process name

processes_dict[key] = value

return processes_dict

有人能把它變漂亮或提出更好的解決方案嗎?

抱歉,我的書寫錯誤。英語不是我的母語。在

總結

以上是生活随笔為你收集整理的python 系统进程_在Python中监视所有系统进程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。