2021-08-27 19:25:43 +00:00
|
|
|
//go:build darwin || linux || netbsd || openbsd
|
2020-03-22 21:08:22 +00:00
|
|
|
// +build darwin linux netbsd openbsd
|
|
|
|
|
|
|
|
package ulimit
|
|
|
|
|
|
|
|
import (
|
2022-06-15 10:06:22 +00:00
|
|
|
"golang.org/x/sys/unix"
|
2020-03-22 21:08:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
supportsFDManagement = true
|
|
|
|
getLimit = unixGetLimit
|
|
|
|
setLimit = unixSetLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
func unixGetLimit() (uint64, uint64, error) {
|
|
|
|
rlimit := unix.Rlimit{}
|
|
|
|
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit)
|
|
|
|
return rlimit.Cur, rlimit.Max, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func unixSetLimit(soft uint64, max uint64) error {
|
|
|
|
rlimit := unix.Rlimit{
|
|
|
|
Cur: soft,
|
|
|
|
Max: max,
|
|
|
|
}
|
|
|
|
return unix.Setrlimit(unix.RLIMIT_NOFILE, &rlimit)
|
|
|
|
}
|