統計Linux下的CPU狀態信息

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()
相關文章
相關標籤/搜索