mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-02 23:18:44 +00:00
Limit pledge.com default virtual mem to total ram
This commit is contained in:
parent
baf51a4a23
commit
7f966de489
3 changed files with 81 additions and 2 deletions
78
examples/sysinfo.c
Normal file
78
examples/sysinfo.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/struct/sysinfo.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int64_t x;
|
||||
char ibuf[21];
|
||||
struct sysinfo si;
|
||||
CHECK_NE(-1, sysinfo(&si));
|
||||
|
||||
printf("%-16s", "uptime");
|
||||
x = si.uptime / (24 * 60 * 60);
|
||||
si.uptime %= 24 * 60 * 60;
|
||||
if (x) {
|
||||
printf(" %ld day%s", x, x == 1 ? "" : "s");
|
||||
}
|
||||
x = si.uptime / (60 * 60);
|
||||
si.uptime %= 60 * 60;
|
||||
if (x) {
|
||||
printf(" %ld hour%s", x, x == 1 ? "" : "s");
|
||||
}
|
||||
x = si.uptime / (60);
|
||||
si.uptime %= 60;
|
||||
if (x) {
|
||||
printf(" %ld minute%s", x, x == 1 ? "" : "s");
|
||||
}
|
||||
x = si.uptime;
|
||||
if (x) {
|
||||
printf(" %ld second%s", x, x == 1 ? "" : "s");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("%-16s %g %g %g\n", "load", //
|
||||
1. / 65536 * si.loads[0], //
|
||||
1. / 65536 * si.loads[1], //
|
||||
1. / 65536 * si.loads[2]); //
|
||||
|
||||
FormatMemorySize(ibuf, si.totalram);
|
||||
printf("%-16s %s\n", "totalram", ibuf);
|
||||
|
||||
FormatMemorySize(ibuf, si.freeram);
|
||||
printf("%-16s %s\n", "freeram", ibuf);
|
||||
|
||||
FormatMemorySize(ibuf, si.sharedram);
|
||||
printf("%-16s %s\n", "sharedram", ibuf);
|
||||
|
||||
FormatMemorySize(ibuf, si.bufferram);
|
||||
printf("%-16s %s\n", "bufferram", ibuf);
|
||||
|
||||
FormatMemorySize(ibuf, si.totalswap);
|
||||
printf("%-16s %s\n", "totalswap", ibuf);
|
||||
|
||||
FormatMemorySize(ibuf, si.freeswap);
|
||||
printf("%-16s %s\n", "freeswap", ibuf);
|
||||
|
||||
printf("%-16s %lu\n", "processes", si.procs);
|
||||
|
||||
FormatMemorySize(ibuf, si.totalhigh);
|
||||
printf("%-16s %s\n", "totalhigh", ibuf);
|
||||
|
||||
FormatMemorySize(ibuf, si.freehigh);
|
||||
printf("%-16s %s\n", "freehigh", ibuf);
|
||||
|
||||
FormatMemorySize(ibuf, si.mem_unit);
|
||||
printf("%-16s %s\n", "mem_unit", ibuf);
|
||||
|
||||
//
|
||||
}
|
|
@ -218,5 +218,3 @@ function bench()
|
|||
print('JsonEncodeObj', Benchmark(JsonEncodeObject))
|
||||
print('BigString', Benchmark(BigString))
|
||||
end
|
||||
|
||||
bench()
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/calls/struct/sched_param.h"
|
||||
#include "libc/calls/struct/sysinfo.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
|
@ -103,11 +104,13 @@ const char *g_promises;
|
|||
|
||||
static void GetOpts(int argc, char *argv[]) {
|
||||
int opt;
|
||||
struct sysinfo si;
|
||||
g_promises = 0;
|
||||
g_proquota = GetCpuCount() * 2;
|
||||
g_fszquota = 256 * 1000 * 1000;
|
||||
g_fszquota = 4 * 1000 * 1000 * 1000;
|
||||
g_memquota = 4L * 1024 * 1024 * 1024;
|
||||
if (!sysinfo(&si)) g_memquota = si.totalram;
|
||||
while ((opt = getopt(argc, argv, "hnNp:u:g:c:C:P:M:F:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
|
|
Loading…
Add table
Reference in a new issue