source: git/Singular/rlimit.c @ 1101a8

spielwiese
Last change on this file since 1101a8 was 1101a8, checked in by Andreas Steenpass <steenpass@…>, 10 years ago
add: create Singular/rlimit.{c,h} for setting resource limits (cherry picked from commit 88e216d8bea3cefdff011bacb24458c88bd1eb32) Signed-off-by: Andreas Steenpass <steenpass@mathematik.uni-kl.de>
  • Property mode set to 100644
File size: 1.1 KB
Line 
1/****************************************
2 * Computer Algebra System SINGULAR     *
3 ****************************************/
4/***************************************************************
5 * File:    rlimit.c
6 * Purpose: set resource limits
7 ***************************************************************/
8
9#include <sys/resource.h>
10
11#include "rlimit.h"
12
13/* raise the maximum number of processes (or threads),
14 * return  0 on success,
15 *        -1 on error
16 */
17int raise_rlimit_nproc()
18{
19#ifdef RLIMIT_NPROC
20  struct rlimit nproc;
21  getrlimit(RLIMIT_NPROC, &nproc);
22  if (nproc.rlim_cur == RLIM_INFINITY
23      || (nproc.rlim_max != RLIM_INFINITY && nproc.rlim_cur >= nproc.rlim_max))
24  {
25    return(-1);
26  }
27  if (nproc.rlim_cur < 512)
28  {
29    nproc.rlim_cur = 512;
30  }
31  if ((nproc.rlim_max == RLIM_INFINITY || 2*nproc.rlim_cur <= nproc.rlim_max)
32      && nproc.rlim_cur < 2*nproc.rlim_cur)
33  {
34    nproc.rlim_cur = 2*nproc.rlim_cur;
35  }
36  else
37  {
38    nproc.rlim_cur = nproc.rlim_max;
39  }
40  int res = setrlimit(RLIMIT_NPROC, &nproc);
41  return(res);
42#else
43  return(-1);
44#endif
45}
Note: See TracBrowser for help on using the repository browser.