scale resource limits same as the ulimit command

This commit is contained in:
Doug MacEachern 2005-07-21 22:19:03 +00:00
parent cad4b55102
commit 0523277687
1 changed files with 15 additions and 9 deletions

View File

@ -934,6 +934,7 @@ int sigar_net_info_get(sigar_t *sigar,
typedef struct { typedef struct {
int resource; int resource;
int factor;
size_t cur; size_t cur;
size_t max; size_t max;
} rlimit_field_t; } rlimit_field_t;
@ -949,18 +950,21 @@ typedef struct {
#endif #endif
static rlimit_field_t sigar_rlimits[] = { static rlimit_field_t sigar_rlimits[] = {
{ RLIMIT_CPU, RlimitOffsets(cpu) }, { RLIMIT_CPU, 1, RlimitOffsets(cpu) },
{ RLIMIT_FSIZE, RlimitOffsets(file_size) }, { RLIMIT_FSIZE, 1024, RlimitOffsets(file_size) },
{ RLIMIT_DATA, RlimitOffsets(data) }, { RLIMIT_DATA, 1024, RlimitOffsets(data) },
{ RLIMIT_STACK, RlimitOffsets(stack) }, { RLIMIT_STACK, 1024, RlimitOffsets(stack) },
{ RLIMIT_CORE, RlimitOffsets(core) }, { RLIMIT_CORE, 1024, RlimitOffsets(core) },
{ RLIMIT_RSS, RlimitOffsets(memory) }, { RLIMIT_RSS, 1024, RlimitOffsets(memory) },
{ RLIMIT_NPROC, RlimitOffsets(processes) }, { RLIMIT_NPROC, 1, RlimitOffsets(processes) },
{ RLIMIT_NOFILE, RlimitOffsets(open_files) }, { RLIMIT_NOFILE, 1, RlimitOffsets(open_files) },
{ RLIMIT_AS, RlimitOffsets(virtual_memory) }, { RLIMIT_AS, 1024, RlimitOffsets(virtual_memory) },
{ -1 } { -1 }
}; };
#define RlimitScale(val) \
if (val != RLIM_INFINITY) val /= r->factor
int sigar_resource_limit_get(sigar_t *sigar, int sigar_resource_limit_get(sigar_t *sigar,
sigar_resource_limit_t *rlimit) sigar_resource_limit_t *rlimit)
{ {
@ -979,6 +983,8 @@ int sigar_resource_limit_get(sigar_t *sigar,
rl.rlim_max = SIGAR_FIELD_NOTIMPL; rl.rlim_max = SIGAR_FIELD_NOTIMPL;
} }
RlimitScale(rl.rlim_cur);
RlimitScale(rl.rlim_max);
RlimitSet(rlimit, r->cur, rl.rlim_cur); RlimitSet(rlimit, r->cur, rl.rlim_cur);
RlimitSet(rlimit, r->max, rl.rlim_max); RlimitSet(rlimit, r->max, rl.rlim_max);
} }