Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, Im writing a c program and i can only open a file so many times until i get a segmentation fault. I am using fopen and fclose to open ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2005
    Posts
    1

    C Probelm: Max number of times can use fopen in a program


    Hi,

    Im writing a c program and i can only open a file so many times until i get a segmentation fault. I am using fopen and fclose to open and close the files. I believe that the max number of file opens i get is 2040(i close each file after opening the next). Is there any way to increase this number ?

    Thanks

    Brent

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    If you close each file after opening the next then it means that at each
    point you have at most 2 files open.So it doesn't matter how many times
    you call fopen.The problem must be something else.Does your programme
    check the return value of fopen and fclose ?

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    I suspect the bug lies elsewhere, and your code is breaking when you've happened to open that number of files. What else is the code doing? Can you reduce to the code to create a minimal failing case and post it here? SEGVs in C programs are usually the result of falling off the end of allocated memory, or misusing/abusing pointers.

    Steve

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •