Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

is this a reliable way to get the number of executing procesors (Intel, AMD, ARM, ... which ever flavor of Unix would run on) from /proc/cpuinfo?

1,008 views
Skip to first unread message

qwert...@syberianoutpost.ru

unread,
Nov 1, 2012, 6:19:22 PM11/1/12
to
_PROX=$(cat /proc/cpuinfo | grep "processor" | tail -n 1 | awk '{ print $3}')
let "_PROX+=1"
echo "\${_PROX}: "${_PROX}
~
Also, once I saw a site similar to the w3.org ones (in which you could check
if your [h|x]tml and schemas are kosher), but for bash scripts POSIX
compliance.
~
I did search for a while, but couldn't find it. What was that site?
~
thanks
lbrtchx
~
unix.shell: is this a reliable way to get the number of executing
procesors (Intel, AMD, ARM, ... which ever flavor of Unix would run on)
from /proc/cpuinfo?

Janis Papanagnou

unread,
Nov 1, 2012, 7:26:00 PM11/1/12
to
On 01.11.2012 23:19, qwert...@syberianoutpost.ru wrote:
> _PROX=$(cat /proc/cpuinfo | grep "processor" | tail -n 1 | awk '{ print $3}')

I am not sure what you're doing here...
You're using cat unnecessarily, grep'ing for patterns, but then retrieve
only one, print the number of the last one, and subsequently adding one
to that number (probably because they are numbered 0..3)?

Why not just count the matching patterns...?

grep -c processor /proc/cpuinfo


Janis

Jerry Peters

unread,
Nov 2, 2012, 4:24:30 PM11/2/12
to
I use "getconf _NPROCESSORS_ONLN" in scripts.

~$ getconf _NPROCESSORS_ONLN
2

Jerry

William Ahern

unread,
Nov 2, 2012, 7:53:14 PM11/2/12
to
That only works on Linux and OS X. It fails on Solaris, FreeBSD, NetBSD, and
OpenBSD.

grep -c processor /proc/cpuinfo works on Linux and NetBSD. That's 2 for 6,
just like _NPROCESSORS_ONLN.

William Ahern

unread,
Nov 2, 2012, 8:03:24 PM11/2/12
to
William Ahern <wil...@wilbur.25thandclement.com> wrote:
> Jerry Peters <je...@example.invalid> wrote:
<snip>
> > I use "getconf _NPROCESSORS_ONLN" in scripts.

> > ~$ getconf _NPROCESSORS_ONLN
> > 2

> That only works on Linux and OS X. It fails on Solaris, FreeBSD, NetBSD, and
> OpenBSD.

> grep -c processor /proc/cpuinfo works on Linux and NetBSD. That's 2 for 6,
> just like _NPROCESSORS_ONLN.

`sysctl hw.ncpu` works on everything but Linux and Solaris. I have VMs for
all 6 systems.

Linux:
1) grep -c process /proc/cpuinfo
2) getconf _NPROCESSORS_ONLN

Solaris:
1) psrinfo -p

OS X:
1) getconf _NPROCESSORS_ONLN
2) sysctl hw.ncpu

NetBSD:
1) grep -c process /proc/cpuinfo
2) sysctl hw.ncpu

OpenBSD:
1) sysctl hw.ncpu

FreeBSD:
1) sysctl hw.ncpu
0 new messages