set_limit.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:13 +0200
changeset 64 993b97c4ad2d
parent 60 47c13ca8c4d0
child 77 49e0babccb23
permissions -rw-r--r--
FORK ERROR in prog_limit and mem2swap: execve overrides the current PID committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
9
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 8
diff changeset
     2
 * test/demos/set_limit.c
c3fecc82ade6 standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 8
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
3
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
60
47c13ca8c4d0 Memory Management
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 51
diff changeset
     6
#include <errno.h>
3
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <sys/resource.h>
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
60
47c13ca8c4d0 Memory Management
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 51
diff changeset
     9
#define MINIMUM (2*1024*1024)
47c13ca8c4d0 Memory Management
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 51
diff changeset
    10
3
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
int set_limit (int megs)
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
{
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
    struct rlimit rlim;
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
51
a03372ef9714 base10.c added and set_limit changed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    15
    megs *= 1024 * 1024;
a03372ef9714 base10.c added and set_limit changed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    16
3
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
    rlim.rlim_cur = megs;
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
    rlim.rlim_max = 1.25 * megs;
60
47c13ca8c4d0 Memory Management
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 51
diff changeset
    19
    if (megs >= MINIMUM)
3
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
        return setrlimit (RLIMIT_AS, &rlim);
8
96d16dfe787a We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 3
diff changeset
    21
60
47c13ca8c4d0 Memory Management
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 51
diff changeset
    22
    errno = ENOMEM;
47c13ca8c4d0 Memory Management
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 51
diff changeset
    23
3
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
    return -1;
820ed7fb9314 database, gauss, lotto, mem2swap, prog_limit moved to demos
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
}