limit_freebsd.go 368 B

123456789101112131415161718192021222324
  1. package sys
  2. import (
  3. "syscall"
  4. )
  5. // SetLimit set NOFILE
  6. func SetLimit(max uint64) error {
  7. var rlimit syscall.Rlimit
  8. err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
  9. if err != nil {
  10. return err
  11. }
  12. rlimit.Cur = int64(max)
  13. rlimit.Max = int64(max)
  14. err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
  15. if err != nil {
  16. return err
  17. }
  18. return nil
  19. }