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
35 #include <sys/resource.h>
39 static void set_ctxlim (int res, long lim, const char *msg)
41 if (call_set_ctxlimit(res,lim)==-1){
42 fprintf (stderr,"Error setting limit \"%s\": %s\n"
43 ,msg,strerror(errno));
50 fprintf (stderr,"setctxlimit version %s\n",VERSION);
52 ,"setctxlimit [ --ctx context ] limits\n"
54 "-n nax opened files\n");
57 int main (int argc, char *argv[])
65 for (i=1; i<argc; i++){
66 const char *arg = argv[i];
67 const char *narg = argv[i+1];
70 if (narg == NULL) narg = "";
72 if (strcmp(arg,"--help")==0){
74 }else if (strcmp(arg,"--ctx")==0){
78 if (call_new_s_context (1,tb,0,0)==-1){
79 fprintf (stderr,"Can't select context %d (%s)\n"
80 ,val,strerror(errno));
83 }else if (strcmp (arg,"-n")==0){
84 set_ctxlim (RLIMIT_NOFILE,val,"Number of opened files");