统计Linux下的CPU状态信息

↘锁芯ラ 提交于 2019-12-22 20:28:06
def cpu():
    all_cpus=[]
    with open('e:/cpu.txt') as f: 
        core={}
        for line in f.readlines():
            ab=line.split(":")
            if len(ab)==2:
                if ab[0].strip()=='processor':
                    if core:
                        all_cpus.append(core.copy())
                    core={}
                    core['proc_id']=ab[1].strip()
                else:
                    core[ab[0].strip()]=ab[1].strip()
    all_cpus.append(core.copy())
    print(all_cpus)
    return all_cpus;
if __name__ =='__main__':
    cpu()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!