tklauser/go-sysconf

GitHub: tklauser/go-sysconf

一个纯 Go 实现的 sysconf 和 pathconf 库,让开发者无需 cgo 即可在多种操作系统上查询系统级配置参数。

Stars: 150 | Forks: 26

# go-sysconf [![Go Reference](https://pkg.go.dev/badge/github.com/tklauser/go-sysconf.svg)](https://pkg.go.dev/github.com/tklauser/go-sysconf) [![GitHub Action Status](https://static.pigsec.cn/wp-content/uploads/repos/cas/c7/c719263266358fdd8a1c44525b9c6c2b8c2b2f3224bc0767bc503767aed57290.svg)](https://github.com/tklauser/go-sysconf/actions?query=workflow%3ATests) 适用于 Go 的 `sysconf` 和 `pathconf`,无需使用 cgo 或外部二进制文件(例如 getconf)。 支持的操作系统:Linux, macOS, DragonflyBSD, FreeBSD, NetBSD, OpenBSD, Solaris/Illumos。 支持所有 POSIX.1 和 POSIX.2 变量,完整列表请参见[参考资料](#references)。 系统范围的变量以 `SC_*` 常量形式提供,并通过 `Sysconf` 函数进行查询。 依赖于路径的变量以 `PC_*` 常量形式提供,并通过 `Pathconf` 或 `Fpathconf` 函数进行查询。 此外,部分操作系统还支持以下非标准变量: | 变量 | 支持平台 | |---|---| | `SC_PHYS_PAGES` | Linux, macOS, FreeBSD, NetBSD, OpenBSD, Solaris/Illumos | | `SC_AVPHYS_PAGES` | Linux, OpenBSD, Solaris/Illumos | | `SC_NPROCESSORS_CONF` | Linux, macOS, FreeBSD, NetBSD, OpenBSD, Solaris/Illumos | | `SC_NPROCESSORS_ONLN` | Linux, macOS, FreeBSD, NetBSD, OpenBSD, Solaris/Illumos | | `SC_UIO_MAXIOV` | Linux | ## 用法 ``` package main import ( "fmt" "github.com/tklauser/go-sysconf" ) func main() { // get clock ticks, this will return the same as C.sysconf(C._SC_CLK_TCK) clktck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) if err == nil { fmt.Printf("SC_CLK_TCK: %v\n", clktck) } // get the maximum filename length for the root directory namemax, err := sysconf.Pathconf("/", sysconf.PC_NAME_MAX) if err == nil { fmt.Printf("PC_NAME_MAX: %v\n", namemax) } } ``` ## 参考资料 * [`sysconf` 的 POSIX 文档](http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html) * [`pathconf` 的 POSIX 文档](http://pubs.opengroup.org/onlinepubs/9699919799/functions/pathconf.html) * [`sysconf(3)` 的 Linux manpage](http://man7.org/linux/man-pages/man3/sysconf.3.html) * [`sysconf` 参数的 glibc 常量](https://www.gnu.org/software/libc/manual/html_node/Constants-for-Sysconf.html)
标签:Bing搜索, EVTX分析, Go, POSIX, Ruby工具, 开发工具库, 日志审计, 系统编程