no files can be opened in a C program

Manish Katiyar mkatiyar at gmail.com
Tue Jul 26 00:52:51 EDT 2011


On Mon, Jul 25, 2011 at 9:41 PM, Manish Katiyar <mkatiyar at gmail.com> wrote:
> On Mon, Jul 25, 2011 at 9:29 PM, Abhijit Pawar <apawar.linux at gmail.com> wrote:
>> Hi Dave,
>> On 07/25/2011 09:20 PM, Dave Hylands wrote:
>>> Hi Abhijit,
>>>
>>> On Mon, Jul 25, 2011 at 6:35 AM, Abhijit Pawar<apawar.linux at gmail.com>  wrote:
>>>> On 07/25/2011 05:29 PM, Naveen Kumar wrote:
>>>>
>>>> You can use command ulimit -a, there you can check the limit for a process.
>>>>
>>>> Thanks,
>>>> Naveen
>>>>
>>>> Ulimit gives 1024 as open file limit. In struct task_struct it has a member
>>>> called struct files_struct *files;
>>>>
>>>> I tried checking for this member and the limit however I am  not able to
>>>> decide correctly why the limit is 1024.
>>>>   Also, is there any distinction between 32 bit and 64 bit systems for this
>>>> limit?
>>> My 64-bit system reports 1024 as well.
>>>
>>> I have no troubles compiling kernels.
>>>
>> Thanks. Yes, on my 64 bit Fedora 15 I get same value as yours.
>>
>> What I am interested in is knowing why the limit is on 1024 File
>> Descriptors? That means 1024 Inodes. AFAIK there isnt anything written
>> in filesystem code which will put this limit of 1024 inodes for a process.
>> This means its very specific to the process.
>> Unfortunately I am know having details on the process front. Is there
>> anything which you or anyone aware in process area because of which this
>> limit is there?
>
> man getdtablesize

and if you trace the kernel code, it comes from the limits of the init
task, which is hard coded during creation. You can get/set these
values using getrlimit/setrlimit.


include/linux/init_task.h
33 #define INIT_SIGNALS(sig) {                                             \
.................
.................
 41         .rlim           = INIT_RLIMITS,
..............

include/asm-generic/resource.h
 72 #define INIT_RLIMITS                                                    \
 73 {                                                                       \
 74         [RLIMIT_CPU]            = {  RLIM_INFINITY,  RLIM_INFINITY },   \
 75         [RLIMIT_FSIZE]          = {  RLIM_INFINITY,  RLIM_INFINITY },   \
 76         [RLIMIT_DATA]           = {  RLIM_INFINITY,  RLIM_INFINITY },   \
 77         [RLIMIT_STACK]          = {       _STK_LIM,   _STK_LIM_MAX },   \
 78         [RLIMIT_CORE]           = {              0,  RLIM_INFINITY },   \
 79         [RLIMIT_RSS]            = {  RLIM_INFINITY,  RLIM_INFINITY },   \
 80         [RLIMIT_NPROC]          = {              0,              0 },   \
 81         [RLIMIT_NOFILE]         = {   INR_OPEN_CUR,   INR_OPEN_MAX },   \
...............
..............

include/linux/fs.h
25 #undef NR_OPEN
 26 #define INR_OPEN_CUR 1024       /* Initial setting for nfile rlimits */
 27 #define INR_OPEN_MAX 4096       /* Hard limit for nfile rlimits */


HTH
-- 
Thanks -
Manish



More information about the Kernelnewbies mailing list