Reputation: 13465
Is there a way to use the unix command line to get the name (or number) of the core that is generating or processing the work?
The purpose is check that a parallel system is actually using all cores and so i want it to return the core name as well as the ip address...
i know the IP address is
ifconfig
I jut need one for cores
This is for both OS X and Linux systems
Upvotes: 0
Views: 102
Reputation: 1364
Use sysctl
for MacOSX, and /proc/cpuinfo
for Linux.
On Linux (RHEL/CentOS), to get number of logical cores, which is different from physical ones when hyperthreading is enabled, count number of siblings up for each physical CPUs.
OSTYPE=`uname`
case $OSTYPE in
Darwin)
NCORES=`sysctl -n hw.physicalcpu`
NLCORES=`sysctl -n hw.logicalcpu`
;;
Linux)
NCORES=`grep processor /proc/cpuinfo | wc -l`
NLCORES=`
grep 'physical id\|siblings' /proc/cpuinfo |
sed 'N;s/\n/ /' |
uniq |
awk -F: '{count += $3} END {print count}'
`
;;
*)
echo "Unsupported OS" >&2
exit 1
;;
esac
echo "Number of cores: $NCORES"
echo "Number of logical cores (HT): $NLCORES"
Tested only on OS X Mountain Lion and CentOS 5. Some fixes may be needed for other systems. Note that this script is not fully tested. Be careful when you use it.
Upvotes: 1