1 /* @(#)resource.h 1.15 21/07/23 Copyright 1995-2021 J. Schilling */ 2 /* 3 * Abstraction from resource limits 4 * 5 * Missing parts for wait3() taken from SunOS 6 * 7 * Copyright (c) 1995-2021 J. Schilling 8 */ 9 /* 10 * The contents of this file are subject to the terms of the 11 * Common Development and Distribution License, Version 1.0 only 12 * (the "License"). You may not use this file except in compliance 13 * with the License. 14 * 15 * See the file CDDL.Schily.txt in this distribution for details. 16 * A copy of the CDDL is also available via the Internet at 17 * http://www.opensource.org/licenses/cddl1.txt 18 * 19 * When distributing Covered Code, include this CDDL HEADER in each 20 * file and include the License file CDDL.Schily.txt from this distribution. 21 */ 22 23 #ifndef _SCHILY_RESOURCE_H 24 #define _SCHILY_RESOURCE_H 25 26 #ifndef _SCHILY_MCONFIG_H 27 #include <schily/mconfig.h> 28 #endif 29 30 #ifndef _SCHILY_STDINT_H 31 #include <schily/stdint.h> /* May be needed for rlim_t */ 32 #endif 33 34 #ifndef _SCHILY_TIME_H 35 #include <schily/time.h> 36 #endif 37 38 /* 39 * Get definitions from system include files 40 */ 41 #ifdef HAVE_SYS_RESOURCE_H 42 #ifndef _INCL_SYS_RESOURCE_H 43 #include <sys/resource.h> 44 #define _INCL_SYS_RESOURCE_H 45 #endif 46 #endif 47 48 #if defined(OS390) || defined(__MVS__) 49 50 #ifdef __never__ /* Compilation fail */ 51 #ifdef HAVE_SYS_DBX_PLUGIN_H /* with suseconds_t redefined */ 52 #ifndef _INCL_SYS_DBX_PLUGIN_H 53 #include <sys/dbx_plugin.h> /* Needed for RLIM_NLIMITS on z/OS */ 54 #define _INCL_SYS_DBX_PLUGIN_H 55 #endif 56 #endif 57 #endif /* __never__ */ 58 59 #if defined(RLIMIT_MEMLIMIT) && !defined(RLIM_NLIMITS) 60 #define RLIM_NLIMITS (RLIMIT_MEMLIMIT+1) 61 #endif 62 #if !defined(RLIM_NLIMITS) 63 #define RLIM_NLIMITS 8 64 #endif 65 66 #endif /* defined(OS390) || defined(__MVS__) */ 67 68 #ifdef __cplusplus 69 extern "C" { 70 #endif 71 72 /* 73 * Now check which definitions are missing and define them localy. 74 */ 75 76 #ifndef RUSAGE_SELF 77 /* 78 * Resource utilization information. 79 */ 80 81 #define RUSAGE_SELF 0 82 #define RUSAGE_CHILDREN -1 83 84 #endif /* RUSAGE_SELF */ 85 86 #ifndef HAVE_STRUCT_RUSAGE 87 88 /* 89 * On a vanilla BSD system, all fields are set. 90 * On other systems, parts may not be supported. 91 * 92 * S: 0 means that the value is 0 on Solaris 93 * S: * means that the value is the sum of rm_asrss on Solaris 94 * 95 * POSIX and BeOS/Haiku define only ru_utime and ru_stime. 96 */ 97 struct rusage { 98 struct timeval ru_utime; /* user time used */ 99 struct timeval ru_stime; /* system time used */ 100 long ru_maxrss; /* maximum resident set size S: 0 */ 101 #define ru_first ru_ixrss 102 long ru_ixrss; /* integral shared memory size S: 0 */ 103 long ru_idrss; /* integral unshared data size S: * */ 104 long ru_isrss; /* integral unshared stack size S: 0 */ 105 long ru_minflt; /* any page faults not requiring I/O */ 106 long ru_majflt; /* any page faults requiring I/O */ 107 long ru_nswap; /* swaps */ 108 long ru_inblock; /* block input operations */ 109 long ru_oublock; /* block output operations */ 110 long ru_msgsnd; /* messages sent */ 111 long ru_msgrcv; /* messages received */ 112 long ru_nsignals; /* signals received */ 113 long ru_nvcsw; /* voluntary context switches */ 114 long ru_nivcsw; /* involuntary " */ 115 #define ru_last ru_nivcsw 116 }; 117 #endif /* HAVE_STRUCT_RUSAGE */ 118 119 #ifndef HAVE_TYPE_RLIM_T 120 #define rlim_t Intmax_t 121 #endif 122 123 #ifndef RLIMIT_CPU 124 /* 125 * Resource limits 126 */ 127 #define RLIMIT_CPU 0 /* cpu time in milliseconds */ 128 #define RLIMIT_FSIZE 1 /* maximum file size */ 129 #define RLIMIT_DATA 2 /* data size */ 130 #define RLIMIT_STACK 3 /* stack size */ 131 #define RLIMIT_CORE 4 /* core file size */ 132 #define RLIMIT_RSS 5 /* resident set size */ 133 134 #define RLIM_NLIMITS 6 /* number of resource limits */ 135 136 #ifndef RLIM_INFINITY 137 #define RLIM_INFINITY 0x7fffffff 138 #endif 139 140 struct rlimit { 141 rlim_t rlim_cur; /* current (soft) limit */ 142 rlim_t rlim_max; /* maximum value for rlim_cur */ 143 }; 144 145 #endif /* RLIMIT_CPU */ 146 147 #ifdef __cplusplus 148 } 149 #endif 150 151 #endif /* _SCHILY_RESOURCE_H */ 152