명령 줄의 프로세서 / 코어 수
Linux에서 프로세서 / 코어 수를 가져 오기 위해 다음 명령을 실행하고 있습니다.
cat /proc/cpuinfo | grep processor | wc -l
작동하지만 우아하게 보이지 않습니다. 개선을 어떻게 제안 하시겠습니까?
nproc
당신이 찾고있는 것입니다.
추가 정보 : http://www.cyberciti.biz/faq/linux-get-number-of-cpus-core-command/
가장 간단한 도구는 glibc와 함께 제공되며 다음과 getconf
같습니다.
$ getconf _NPROCESSORS_ONLN
4
나는 당신이 제공하는 방법이 Linux에서 가장 이식성이 있다고 생각합니다. 대신 불필요한 산란 cat
및 wc
프로세스를, 당신은 조금을 단축 할 수 있습니다 :
$ grep --count ^processor /proc/cpuinfo
2
이를 수행하여 Linux 및 OS X에서 작동하도록하려면 다음을 수행 할 수 있습니다.
CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
최신 커널에서는 /sys/devices/system/cpu/
인터페이스를 사용하여 더 많은 정보를 얻을 수도 있습니다 .
$ ls /sys/devices/system/cpu/
cpu0 cpufreq kernel_max offline possible present release
cpu1 cpuidle modalias online power probe uevent
$ cat /sys/devices/system/cpu/kernel_max
255
$ cat /sys/devices/system/cpu/offline
2-63
$ cat /sys/devices/system/cpu/possible
0-63
$ cat /sys/devices/system/cpu/present
0-1
$ cat /sys/devices/system/cpu/online
0-1
참조 공식 문서를 무엇을 모든 평균에 대한 자세한 내용은.
누군가 "프로세서 / 코어 수"를 물으면 2 개의 답변이 요청됩니다. "프로세서"의 수는 시스템의 소켓에 설치된 물리적 수입니다.
"코어"의 수는 물리적 코어입니다. 하이퍼 스레딩 (가상) 코어는 포함되지 않을 것입니다 (적어도 내 마음에는). 스레드 풀을 사용하여 많은 프로그램을 작성하는 사람은 실제 코어 대 코어 / 하이퍼 스레드 수를 알아야합니다. 즉, 다음 스크립트를 수정하여 필요한 답변을 얻을 수 있습니다.
#!/bin/bash
MODEL=`cat /cpu/procinfo | grep "model name" | sort | uniq`
ALL=`cat /proc/cpuinfo | grep "bogo" | wc -l`
PHYSICAL=`cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l`
CORES=`cat /proc/cpuinfo | grep "cpu cores" | sort | uniq | cut -d':' -f2`
PHY_CORES=$(($PHYSICAL * $CORES))
echo "Type $MODEL"
echo "Processors $PHYSICAL"
echo "Physical cores $PHY_CORES"
echo "Including hyperthreading cores $ALL"
하이퍼 스레딩을 지원하는 6 개의 물리적 코어가 각각있는 2 개의 모델 Xeon X5650 물리적 프로세서가있는 시스템의 결과 :
Type model name : Intel(R) Xeon(R) CPU X5650 @ 2.67GHz
Processors 2
Physical cores 12
Including hyperthreading cores 24
하이퍼 스레딩을 지원하지 않는 물리적 코어가 각각 4 개있는 mdeol Xeon E5472 프로세서 2 개가있는 컴퓨터에서
Type model name : Intel(R) Xeon(R) CPU E5472 @ 3.00GHz
Processors 2
Physical cores 8
Including hyperthreading cores 8
The lscpu(1)
command provided by the util-linux project might also be useful:
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 58
Model name: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
Stepping: 9
CPU MHz: 3406.253
CPU max MHz: 3600.0000
CPU min MHz: 1200.0000
BogoMIPS: 5787.10
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 4096K
NUMA node0 CPU(s): 0-3
This is for those who want to a portable way to count cpu cores on *bsd, *nix or solaris (haven't tested on aix and hp-ux but should work). It has always worked for me.
dmesg | \
egrep 'cpu[. ]?[0-9]+' | \
sed 's/^.*\(cpu[. ]*[0-9]*\).*$/\1/g' | \
sort -u | \
wc -l | \
tr -d ' '
solaris grep
& egrep
don't have -o
option so sed
is used instead.
Another one-liner, without counting hyper-threaded cores:
lscpu | awk -F ":" '/Core/ { c=$2; }; /Socket/ { print c*$2 }'
If you need an os independent method, works across Windows and Linux. Use python
$ python -c 'import multiprocessing as m; print m.cpu_count()'
16
참고URL : https://stackoverflow.com/questions/19619582/number-of-processors-cores-in-command-line
'Programming' 카테고리의 다른 글
객체가 기본 유형인지 확인 (0) | 2020.08.08 |
---|---|
Sublime Text Editor에서 특정 확장자를 가진 파일을 숨기시겠습니까? (0) | 2020.08.08 |
마지막 자식 선택기 사용 (0) | 2020.08.08 |
Java에서 현재 날짜를 문자열로 변환하는 방법은 무엇입니까? (0) | 2020.08.08 |
선언되지 않은 식별자 'kUTTypeMovie'사용 (0) | 2020.08.08 |