limit.go 354 B

123456789101112131415161718192021222324
  1. package sys
  2. import (
  3. "syscall"
  4. )
  5. // SetLimit set NOFILE
  6. func SetLimit(uint64 max) 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 = max
  13. rlimit.Max = max
  14. err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
  15. if err != nil {
  16. return err
  17. }
  18. return nil
  19. }