Not logged in
Log in now
Create an account
Subscribe to LWN
Pencil, Pencil, and Pencil
Dividing the Linux desktop
LWN.net Weekly Edition for June 13, 2013
A report from pgCon 2013
Little things that matter in language design
FACT: systemd has had at least one well publicized failure to do the job it is responsible for so severe the linux kernel had to be changed because the systemd maintainers could not get their act together.
There are real reasons to question systemd
Posted Jan 28, 2013 17:52 UTC (Mon) by mezcalero (subscriber, #45103)
Posted Jan 29, 2013 11:27 UTC (Tue) by nix (subscriber, #2304)
Posted Jan 29, 2013 13:12 UTC (Tue) by eru (subscriber, #2753)
In that case I would like to know of some alternate, more stable way to get this information - and preferably without adding dependencies on some heavy-duty libraries or middleware, since the program currently depends on nothing but its own code, the standard C library, and pthreads.
Posted Jan 29, 2013 13:45 UTC (Tue) by cortana (subscriber, #24596)
Posted Jan 29, 2013 13:53 UTC (Tue) by khim (subscriber, #9252)
Posted Jan 29, 2013 16:20 UTC (Tue) by nix (subscriber, #2304)
Posted Jan 29, 2013 16:54 UTC (Tue) by cesarb (subscriber, #6266)
Posted Jan 29, 2013 19:01 UTC (Tue) by nix (subscriber, #2304)
getconf _NPROCESSORS_CONF (or _NPROCESSORS_ONLN) is the thing to use (or, from a program, sysconf(_SC_NPROCESSORS_CONF) et seq. This is in glibc, so has a stability guarantee that is worth something. Let it figure out where to go for the answer.
Posted Jan 29, 2013 20:10 UTC (Tue) by eru (subscriber, #2753)
Posted Jan 29, 2013 16:29 UTC (Tue) by cesarb (subscriber, #6266)
Copying an old Stack Overflow answer of mine:
The definitive resource for /sys is Documentation/sysfs-rules.txt. The definitive resource for /proc/sys is Documentation/sysctl/. The definitive resource for the rest of /proc appears to be Documentation/filesystems/proc.txt. The rest of the Documentation/ directory in the Linux kernel source has other interesting information. In particular, Documentation/ABI/ mentions the stability of each interface.
(Unfortunately for your use case, I found nothing about /proc/cpuinfo in these files, and I know that the output is very different depending on the architecture, so it is probably not stable. The /sys/devices/system/cpu directory has some of that information, however, including how many cores there are, and should be the same for all architectures, so I would recommend looking there first and using /proc/cpuinfo as a fallback.)
Posted Jan 29, 2013 12:16 UTC (Tue) by HelloWorld (guest, #56129)
Posted Jan 29, 2013 13:30 UTC (Tue) by lsl (subscriber, #86508)
> The kernel-exported sysfs exports internal kernel implementation details
> and depends on internal kernel structures and layout. It is agreed upon
> by the kernel developers that the Linux kernel does not provide a stable
> internal API. Therefore, there are aspects of the sysfs interface that
> may not be stable across kernel releases.
Posted Jan 28, 2013 19:07 UTC (Mon) by smurf (subscriber, #17840)
(b) not everybody religiously reads LWN and/or can read minds, so kindly name names.
Posted Jan 29, 2013 0:40 UTC (Tue) by robert_s (subscriber, #42402)
Posted Jan 30, 2013 19:12 UTC (Wed) by ttelford (subscriber, #44176)
Posted Jan 30, 2013 19:45 UTC (Wed) by raven667 (subscriber, #5198)
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds