I'm working on a SunOS 5.11/Solaris 11.3 machine. I have a bash script that calculates and exports CPU frequency because I use it frequently in some test scripts.
Here are the two lines of interest:
solaris:~$ CPU_FREQ=$(psrinfo -v 2>/dev/null | grep 'MHz' | head -1 | awk '{print $6}')
solaris:~$ echo $CPU_FREQ
3000
solaris:~$ CPU_FREQ=$(awk "BEGIN {print $CPU_FREQ/1024/1024}")
^C
Why does the awk command hang under Solaris? And what should I be doing different?
Here's the larger view of the script. It works well under Linux, OS X and the BSDs.
IS_LINUX=$(uname -s | grep -i -c linux)
IS_DARWIN=$(uname -s | grep -i -c darwin)
IS_SOLARIS=$(uname -s | grep -i -c sunos)
# 2.0 GHz or 2.0/1024/1024/1024
CPU_FREQ=1.8189894
if [ "$IS_LINUX" -ne "0" ] && [ -e "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" ]; then
CPU_FREQ=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq)
CPU_FREQ=$(awk "BEGIN {print $CPU_FREQ/1024/1024}")
elif [ "$IS_DARWIN" -ne "0" ]; then
CPU_FREQ=$(sysctl -a 2>/dev/null | grep 'hw.cpufrequency' | head -1 | awk '{print $3}')
CPU_FREQ=$(awk "BEGIN {print $CPU_FREQ/1024/1024/1024}")
elif [ "$IS_SOLARIS" -ne "0" ]; then
CPU_FREQ=$(psrinfo -v 2>/dev/null | grep 'MHz' | head -1 | awk '{print $6}')
CPU_FREQ=$(awk "BEGIN {print $CPU_FREQ/1024}")
fi
# Used by Crypto++ benchmarks
export CPU_SPEED=$CPU_FREQ
Here's the output of psrinfo:
$ psrinfo -v
Status of virtual processor 0 as of: 06/07/2016 18:23:29
on-line since 06/07/2016 14:28:28.
The i386 processor operates at 3000 MHz,
and has an i387 compatible floating point processor.
Status of virtual processor 1 as of: 06/07/2016 18:23:29
on-line since 06/07/2016 14:28:34.
The i386 processor operates at 3000 MHz,
and has an i387 compatible floating point processor.
Status of virtual processor 2 as of: 06/07/2016 18:23:29
on-line since 06/07/2016 14:28:34.
The i386 processor operates at 3000 MHz,
and has an i387 compatible floating point processor.
Status of virtual processor 3 as of: 06/07/2016 18:23:29
on-line since 06/07/2016 14:28:34.
The i386 processor operates at 3000 MHz,
and has an i387 compatible floating point processor.