set_limit.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Tue, 12 May 2009 12:06:26 +0200
changeset 91 1181deef3bd6
parent 77 49e0babccb23
child 167 7c6b221900bf
permissions -rw-r--r--
fixed a typo in mem2swap.c 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
/**
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 60
diff changeset
     2
 * set_limit.c
9
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
}