"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/core-limit.c" (15 Mar 2019, 2219 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "core-limit.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) 2014-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include "stress-ng.h"
   26 
   27 static const int limits[] = {
   28 #if defined(RLIMIT_AS)
   29     RLIMIT_AS,
   30 #endif
   31 #if defined(RLIMIT_CPU)
   32     RLIMIT_CPU,
   33 #endif
   34 #if defined(RLIMIT_DATA)
   35     RLIMIT_DATA,
   36 #endif
   37 #if defined(RLIMIT_FSIZE)
   38     RLIMIT_FSIZE,
   39 #endif
   40 #if defined(RLIMIT_LOCKS)
   41     RLIMIT_LOCKS,
   42 #endif
   43 #if defined(RLIMIT_MEMLOCK)
   44     RLIMIT_MEMLOCK,
   45 #endif
   46 #if defined(RLIMIT_MSGQUEUE)
   47     RLIMIT_MSGQUEUE,
   48 #endif
   49 #if defined(RLIMIT_NICE)
   50     RLIMIT_NICE,
   51 #endif
   52 #if defined(RLIMIT_NOFILE)
   53     RLIMIT_NOFILE,
   54 #endif
   55 #if defined(RLIMIT_NPROC)
   56     RLIMIT_NPROC,
   57 #endif
   58 #if defined(RLIMIT_RSS)
   59     RLIMIT_RSS,
   60 #endif
   61 #if defined(RLIMIT_RTPRIO)
   62     RLIMIT_RTPRIO,
   63 #endif
   64 #if defined(RLIMIT_RTTIME)
   65     RLIMIT_RTTIME,
   66 #endif
   67 #if defined(RLIMIT_SIGPENDING)
   68     RLIMIT_SIGPENDING,
   69 #endif
   70 #if defined(RLIMIT_STACK)
   71     RLIMIT_STACK
   72 #endif
   73 };
   74 
   75 /*
   76  *  set_max_limits()
   77  *  push rlimits to maximum values allowed
   78  *  so we can stress a system to the maximum,
   79  *  we ignore any rlimit errors.
   80  */
   81 void set_max_limits(void)
   82 {
   83     size_t i;
   84 
   85     for (i = 0; i < SIZEOF_ARRAY(limits); i++) {
   86         struct rlimit rlim;
   87 
   88         if (getrlimit(limits[i], &rlim) < 0)
   89             continue;
   90         rlim.rlim_cur = rlim.rlim_max;
   91         (void)setrlimit(limits[i], &rlim);
   92     }
   93 }
   94