3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on setctxlimit.cc by Jacques Gelinas
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 Set the global per context limit of a resource (memory, file handle).
22 This utility can do it either for the current context or a selected
25 It uses the same options as ulimit, when possible
31 #include <sys/resource.h>
35 static void set_ctxlim (int res, long lim, const char *msg)
37 if (call_set_ctxlimit(res,lim)==-1){
38 fprintf (stderr,"Error setting limit \"%s\": %s\n"
39 ,msg,strerror(errno));
46 fprintf (stderr,"setctxlimit version %s\n",VERSION);
48 ,"setctxlimit [ --ctx context ] limits\n"
50 "-n nax opened files\n");
53 int main (int argc, char *argv[])
61 for (i=1; i<argc; i++){
62 const char *arg = argv[i];
63 const char *narg = argv[i+1];
66 if (narg == NULL) narg = "";
68 if (strcmp(arg,"--help")==0){
70 }else if (strcmp(arg,"--ctx")==0){
74 if (call_new_s_context (1,tb,0,0)==-1){
75 fprintf (stderr,"Can't select context %d (%s)\n"
76 ,val,strerror(errno));
79 }else if (strcmp (arg,"-n")==0){
80 set_ctxlim (RLIMIT_NOFILE,val,"Number of opened files");