LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-20-2006, 06:57 AM   #1
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
increasing maximum no of file descriptors


hi all,

I tried increasing the maximum no of file descriptors that can be opened per process
which was initially 256 (through ulimit -Sa )
to 512
ulimit -Sa n 512

even after increasing the soft limit to 512
i am unable to have more than 256 file descriptors per process

here is the code that i tried.

Could you please help with this?
Thanks.

Code:
# include <stdio.h>

int main()
{
FILE *fp[300];
int i=0;
while (1)
{
fp[i]=fopen("checkfile.c", "r");
if ( fp[i] == NULL )
{
fprintf(stderr, "now the i value is %d\n", i);
exit (0);
}
fprintf(stderr, "Descriptor: %d done\n", i);
if( i % 10 == 0)
{
fprintf(stderr, "\n\n\n Sleeping \n\n");
sleep (1);
}
i++;
}
return 0;
}
 
Old 02-20-2006, 08:41 AM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Interesting: I tried your program and got a seg. fault after 299.

Oh, I also got this:
Code:
$ ulimit -n
1024
and noticed this line in man ulimit:
Quote:
-n The maximum number of open file descriptors (most systems do not allow this value to be set)
As an aside, your syntax (as written: ulimit -Sa n 512) seems to have an extra space in it, but I suspect that that was a typo.
 
Old 02-20-2006, 08:48 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
As a user you generally can't ulimit upwards.

Even if you ulimit downwards you can't ulimit yourself back up again, i believe.
 
Old 02-20-2006, 10:12 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
... and if you're trying to open that many file-descriptors at one time, something is wrong with your design, imho...
 
Old 02-20-2006, 11:09 AM   #5
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Try with "ulimit -Hn" first, to raise the hard limits, then use "-Sn" See "help ulimit" to see why. To raise them at system level, run "sysctl -a | grep file", then you can increase the proper key with sysctl -w or via the /proc filesystem (which may be /proc/sys/fs/file-max).
 
Old 02-21-2006, 07:17 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
of course I could be wrong
 
Old 02-21-2006, 07:47 AM   #7
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by PTrenholme
As an aside, your syntax (as written: ulimit -Sa n 512) seems to have an extra space in it, but I suspect that that was a typo.
ya, you are correct that was a typo
i intermixed two steps

i dont want to play with the hard limits
thats i used the soft limits

that was actually,
Code:
ulimit -Sn 512
and
Code:
ulimit -a
 
Old 02-21-2006, 07:51 AM   #8
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by bigearsbilly
As a user you generally can't ulimit upwards.

Even if you ulimit downwards you can't ulimit yourself back up again, i believe.
i believe that is not that way,
as long as the soft limit dont cross the hard limit then there is no problem
literally the hard limit cannot be crossed ( would be errored out )

moreover, the limit increase that i had tried is only on soft limits but still as a user i can increase the hard limit

if ulimit command is made use to increase or decrease the limits without specifying hard or soft limits it applies to both
 
Old 02-21-2006, 08:04 AM   #9
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by primo
Try with "ulimit -Hn" first, to raise the hard limits, then use "-Sn" See "help ulimit" to see why. To raise them at system level, run "sysctl -a | grep file", then you can increase the proper key with sysctl -w or via the /proc filesystem (which may be /proc/sys/fs/file-max).
its my mistake that I hadnot mentioned the distribution
its solaris 5.9
and the equivalient of sysctl i have to run only sysdef
for the file equivalent in solaris is /etc/system. I couldnot find any options in sysdef to change existing limits.
Please correct if I am wrong somewhere.
 
Old 02-21-2006, 10:02 AM   #10
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You are bound by a libc limitation, not a system one.

There is no limitation with libc when Solaris run in 64 bit mode, available on 64 bit processors, like UltraSPARC or AMD64.

Actually, there is a limit around 2 billions, but I doubt you'll hit that level

When in 32 bit mode, libc limits you to 256 open files per process.

Please note that you can still open much more files, but to do that you need to use open/read/write/close calls, not fopen,fclose and the likes.

Should you need a libc like facility, you may have a look at sfio (I never tested it though):

http://www.research.att.com/sw/tools/sfio/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Increasing File Descriptors Geoffrey_Firmin Slackware 5 04-21-2008 09:48 AM
Increasing Maximum upload size in php aarajthomas Programming 8 01-16-2006 12:46 AM
[lilo] increasing the maximum image size MD3 Linux - Software 1 04-22-2005 08:18 AM
file descriptors node047 Linux - Newbie 1 03-29-2005 05:47 AM
unix file descriptors versus c FILE pointers nodger Programming 9 11-25-2004 07:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration