...
1# go-sysconf
2
3[](https://pkg.go.dev/github.com/tklauser/go-sysconf)
4[](https://github.com/tklauser/go-sysconf/actions?query=workflow%3ATests)
5
6`sysconf` for Go, without using cgo or external binaries (e.g. getconf).
7
8Supported operating systems: Linux, macOS, DragonflyBSD, FreeBSD, NetBSD, OpenBSD, Solaris/Illumos.
9
10All POSIX.1 and POSIX.2 variables are supported, see [References](#references) for a complete list.
11
12Additionally, the following non-standard variables are supported on some operating systems:
13
14| Variable | Supported on |
15|---|---|
16| `SC_PHYS_PAGES` | Linux, macOS, FreeBSD, NetBSD, OpenBSD, Solaris/Illumos |
17| `SC_AVPHYS_PAGES` | Linux, OpenBSD, Solaris/Illumos |
18| `SC_NPROCESSORS_CONF` | Linux, macOS, FreeBSD, NetBSD, OpenBSD, Solaris/Illumos |
19| `SC_NPROCESSORS_ONLN` | Linux, macOS, FreeBSD, NetBSD, OpenBSD, Solaris/Illumos |
20| `SC_UIO_MAXIOV` | Linux |
21
22## Usage
23
24```Go
25package main
26
27import (
28 "fmt"
29
30 "github.com/tklauser/go-sysconf"
31)
32
33func main() {
34 // get clock ticks, this will return the same as C.sysconf(C._SC_CLK_TCK)
35 clktck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK)
36 if err == nil {
37 fmt.Printf("SC_CLK_TCK: %v\n", clktck)
38 }
39}
40```
41
42## References
43
44* [POSIX documenation for `sysconf`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html)
45* [Linux manpage for `sysconf(3)`](http://man7.org/linux/man-pages/man3/sysconf.3.html)
46* [glibc constants for `sysconf` parameters](https://www.gnu.org/software/libc/manual/html_node/Constants-for-Sysconf.html)
View as plain text