SysResource.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2016-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #ifndef _WIN32
  18. #include <sys/resource.h>
  19. #else
  20. #include <cstdint>
  21. #include <folly/portability/SysTime.h>
  22. #define PRIO_PROCESS 1
  23. #define RLIMIT_CORE 0
  24. #define RLIMIT_NOFILE 0
  25. #define RLIMIT_DATA 0
  26. #define RLIMIT_STACK 3
  27. #define RLIM_INFINITY SIZE_MAX
  28. #define RUSAGE_SELF 0
  29. #define RUSAGE_CHILDREN 0
  30. #define RUSAGE_THREAD 0
  31. using rlim_t = size_t;
  32. struct rlimit {
  33. rlim_t rlim_cur;
  34. rlim_t rlim_max;
  35. };
  36. struct rusage {
  37. timeval ru_utime;
  38. timeval ru_stime;
  39. long ru_maxrss;
  40. long ru_ixrss;
  41. long ru_idrss;
  42. long ru_isrss;
  43. long ru_minflt;
  44. long ru_majflt;
  45. long ru_nswap;
  46. long ru_inblock;
  47. long ru_oublock;
  48. long ru_msgsnd;
  49. long ru_msgrcv;
  50. long ru_nsignals;
  51. long ru_nvcsw;
  52. long ru_nivcsw;
  53. };
  54. extern "C" {
  55. int getrlimit(int type, rlimit* dst);
  56. int getrusage(int who, rusage* usage);
  57. int setrlimit(int type, rlimit* src);
  58. int getpriority(int which, int who);
  59. int setpriority(int which, int who, int value);
  60. }
  61. #endif