如何在 SunOs 系统上使用 python 获取 CPU 信息?
How do I get CPU information by using python on SunOs systems?
我想以编程方式获取 CPU 信息。我已经为 Linux 编写了一个解决方案,但我需要为 SunOS 构建一个类似的解决方案。有人知道吗?
def getCpusInfo():
cpuinfos = []
cpuinfo = {}
for line in open('/proc/cpuinfo').readlines():
line = line.strip()
dual = line.split(':')
key = dual[0].replace('\t', '')
if (key == 'processor'):
cpuinfo = {}
cpuinfos.append(cpuinfo)
elif (len(dual)>1):
cpuinfo[key] = trim(dual[1])
return cpuinfos
cpusinfo = getCpusInfo();
print "Model = " + cpusinfo[0]['model name']
print "Quantity = " + str(len(cpusinfo))
print "Cores = " + cpusinfo[0]['cpu cores']
print "Threads = " + cpusinfo[0]['siblings']
我可以在 bash 中找到解决方案,因此它很容易移植到 python。
感谢评论中的帮助
CORES_F=`/usr/sbin/psrinfo -p`
PROCESSOR=`/usr/sbin/psrinfo -vp | head -1 | awk '{print }'`
MODEL=`/usr/sbin/psrinfo -pv | tail -1 | awk '{print }'`
echo "Model = " $MODEL
echo "Cores = " $CORES_F
echo "Threads = " $PROCESSOR
它仍然缺少 cpu 个数量,但就我而言,我不需要再保存此信息。
我想以编程方式获取 CPU 信息。我已经为 Linux 编写了一个解决方案,但我需要为 SunOS 构建一个类似的解决方案。有人知道吗?
def getCpusInfo():
cpuinfos = []
cpuinfo = {}
for line in open('/proc/cpuinfo').readlines():
line = line.strip()
dual = line.split(':')
key = dual[0].replace('\t', '')
if (key == 'processor'):
cpuinfo = {}
cpuinfos.append(cpuinfo)
elif (len(dual)>1):
cpuinfo[key] = trim(dual[1])
return cpuinfos
cpusinfo = getCpusInfo();
print "Model = " + cpusinfo[0]['model name']
print "Quantity = " + str(len(cpusinfo))
print "Cores = " + cpusinfo[0]['cpu cores']
print "Threads = " + cpusinfo[0]['siblings']
我可以在 bash 中找到解决方案,因此它很容易移植到 python。
感谢评论中的帮助
CORES_F=`/usr/sbin/psrinfo -p`
PROCESSOR=`/usr/sbin/psrinfo -vp | head -1 | awk '{print }'`
MODEL=`/usr/sbin/psrinfo -pv | tail -1 | awk '{print }'`
echo "Model = " $MODEL
echo "Cores = " $CORES_F
echo "Threads = " $PROCESSOR
它仍然缺少 cpu 个数量,但就我而言,我不需要再保存此信息。