Operating System - HP-UX
1824219 Members
4129 Online
109669 Solutions
New Discussion юеВ

maxfiles and maxfiles_lim vs nofiles via ulimit -a

 
Stone666
Occasional Contributor

maxfiles and maxfiles_lim vs nofiles via ulimit -a

Hi,

I have a question about maxfiles / maxfiles_lim kernel parameter isuse.

From man page, I know the maxfiles is soft limit and maxfiles_lim is hard limit, but, what's the time that user process will apply those two limitation ? I try to write a program and open many files and my program can allocate files more than maxfiles_lim setting, why ? and I also find in my shell environment, it depends on nofiles setting from ulimit -a command.

For example :

maxfiles 60
maxfiles_lim 1024
nofiles (ulimit -a) 1500

Then my program can allocate 1500 files simultaneously, why it not stop in 1024 ? this problem really confuse me.

thanks.
6 REPLIES 6
Yogeeraj_1
Honored Contributor

Re: maxfiles and maxfiles_lim vs nofiles via ulimit -a

hi,

did you use a superuser account or non-superuser account to run the program?

revert

regards
yogeeraj

No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Stone666
Occasional Contributor

Re: maxfiles and maxfiles_lim vs nofiles via ulimit -a

I use regular user for this testing, not root
Muthukumar_5
Honored Contributor

Re: maxfiles and maxfiles_lim vs nofiles via ulimit -a

maxfiles 60
maxfiles_lim 1024 are the kernel setting of which used to control maximum number of files.

nofiles setting with soft limit will use maximum of 60. nofiles with hard limit will use maximum of 1024 files.

You can even set nofiles to *unlimited* so that it is not meant to to use unlimited open files. It will have limit based on maxfiles and maxfiles_lim setting.

hard and soft limit setting view:
http://www.faqs.org/faqs/hp/hpux-faq/section-144.html

To monitor open files then,

# sar -v 1

use lsof tool too.

hth.
Easy to suggest when don't know about the problem!
Stone666
Occasional Contributor

Re: maxfiles and maxfiles_lim vs nofiles via ulimit -a

Hi,

Thanks. But I really get the testing result over my hard limit, here is my testing program.

$ more create.c
#include

main()
{
FILE *f[2000];
char *filename="test";
char buffer[10];
int i;

for (i=0; i < 2000; i++) {
printf("Number of tries: %d :", i);
if ((f[i]=fopen(filename, "rt")) == NULL)
printf("Failed\n");
else
printf("Success\n");
}

gets(buffer);

for (i=0; i < 2000; i++) {
fclose(f[i]);
}
}

And, maxfiles and maxfiles_lim
maxfiles - - 60
maxfiles_lim - - 1024

nofiles(descriptors) 1500

Here is the partial output

Number of tries: 1491 :Success
Number of tries: 1492 :Success
Number of tries: 1493 :Success
Number of tries: 1494 :Success
Number of tries: 1495 :Success
Number of tries: 1496 :Success
Number of tries: 1497 :Failed
Number of tries: 1498 :Failed
Number of tries: 1499 :Failed
Number of tries: 1500 :Failed
Number of tries: 1501 :Failed
Number of tries: 1502 :Failed
Number of tries: 1503 :Failed
Armin Kunaschik
Esteemed Contributor

Re: maxfiles and maxfiles_lim vs nofiles via ulimit -a

Just a quick question:
You're always opening the same file.
Did you try with different filenames?
And now for something completely different...
Jeff Lightner_1
Frequent Advisor

Re: maxfiles and maxfiles_lim vs nofiles via ulimit -a

Are you sure the files are all still open concurrently? The maxfiles deal with concurrent open files.

You might want to run lsof in a separate window and let it count your open files. Perhaps some of what you are opening are closing before you get to the end of the loop.