How to increase the limit of "maximum open files" in C?

The default limit for the max open files on Mac OS X is 256 (ulimit -n) and my application needs about 400 file handlers.
I tried to change the limit with setrlimit() but even if the function executes correctly, i'm still limited to 256.
Here is the test program I use (compiled with gcc):
#include <stdio.h>
#include <sys/resource.h>
main()
struct rlimit rlp;
FILE *fp[10000];
int i;
getrlimit(RLIMIT_NOFILE, &rlp);
printf("before %d %d
", rlp.rlim_cur, rlp.rlim_max);
rlp.rlim_cur = 10000;
setrlimit(RLIMIT_NOFILE, &rlp);
getrlimit(RLIMIT_NOFILE, &rlp);
printf("after %d %d
", rlp.rlim_cur, rlp.rlim_max);
for(i=0;i<10000;i++) {
fp = fopen("a.out", "r");
if(fp==0) { printf("failed after %d
", i); break; }
and the output is:
before 256 -1
after 10000 -1
failed after 253
I cannot ask the people who use my application to poke inside a /etc file or something. I need the application to do it by itself.

There is no reason to have more than 256 files open. Whatever you are doing, you are doing it wrong.
The setrlimit() function only applies to new processes. It does not affect the current process. You can either run "ulimit -n 10000" in the shell and then start your program or split your program into two segments:
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <unistd.h>
int main(void)
struct rlimit rlp;
int r;
r = getrlimit(RLIMIT_NOFILE, &rlp);
if (r == -1)
perror("getrlimit()");
exit(1);
printf("before %d %d
", (int) rlp.rlim_cur, (int) rlp.rlim_max);
rlp.rlim_cur = 10000;
/* I'm curious how anyone ever expected it to work or got it to work
without setting the max, because it sure seems to be required. */
rlp.rlim_max = 10000;
r = setrlimit(RLIMIT_NOFILE, &rlp);
if (r == -1)
perror("setrlimit()");
exit(1);
r = getrlimit(RLIMIT_NOFILE, &rlp);
if (r == -1)
perror("setrlimit()");
exit(1);
printf("after %d %d
", (int) rlp.rlim_cur, (int) rlp.rlim_max);
return execl("/tmp/f", "/tmp/f", NULL);
And the source to the "f" program is:
#include <stdio.h>
int main(void)
FILE *fp[10000];
int i;
for(i = 0; i < 10000; i++)
fp = fopen("a.out", "r");
if (fp == NULL)
perror("fopen()");
fprintf(stderr, "i == %d
", i);
return 1;
return 0;
[jdaniel@Pele:584] /tmp $ a.out
before 256 256
setrlimit(): Operation not permitted
[jdaniel@Pele:585] /tmp $ sudo a.out
before 256 256
after 10000 10000
fopen(): Too many open files
i == 9997
As you can see, it is convoluted and a real hassle. It isn't a bug in MacOS X 10.6 or any other version.
So, I repeat my question yet again. Why do you want to open more than 256 files? It is, of course, a rhetorical question. Don't do it. If you feel you need more than 256 open files, review your architecture and correct it.

Similar Messages

  • How to increase the limit of maximim connections that the iMS will accept

    how to increase the limit of maximim smtp connections that the iMS will accept & route the mails for specific domain on different mta like iMS will accpet mails on 192.168.1.5|25 & route all @mydomain.com's mails towards 192.168.1.55|25. although I am able to route the mails but to know how to increase the limit of maximum connection & maximum chiild processes per connection.
    Thanks

    Best thing for you to do is read the tuning guide, found here:
    http://ims.balius.com/downloads.php#tuning_guide
    Please note, this site does not work with IE. It's not a Sun site, but has the best tuning guide available.
    You may end up increasing maxjobs for your channels, increasing the POOL that the jobs are pulled from, etc. It's all well covered in the guide, as are some OS related tuning tips.
    Strongly recommended.

  • How to increase the speed of video (avi file) using labview

    How to increase the speed of video (.avi file) using labview? I have  tried this by skiping alternate frames. also I have used  minimum time delay.Is there  any other option for which i can go?
    please suggest me........... 

    Are you using NI Vision IMAQ AVI Read Frame or anther method to read the AVI file?
    Matthew Fitzsimons
    Certified LabVIEW Architect
    LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison

  • How to increase the limit keys?

    Hi,
    I have problem in PA4. The table GLPCAX has been already partitioned and it has 21 parts. The problem is that 21st part of the table gradually increasing size 47GB.
    We don't know how to re-balance or increase the limit key values in SAP side? Can you please provide us an OSS note to increase the limit key
    values.
    Thanks,
    Rajesh

    Hi Rajesh,
    i don't know how to do it in SAP. But we rebalance the table on z/OS, if it is necessary:
    REORG TABLESPACE "<database>"."<tablespace>" PART (1:<n>) REBALANCE
         COPYDDN(CP1)
         SORTDATA LOG NO SORTKEYS
         SHRLEVEL REFERENCE
         TIMEOUT TERM
         STATISTICS TABLE(ALL)  SAMPLE 25 UPDATE ALL
    hth
    Kay

  • How to increase the size of Redo log files?

    Hi All,
    I have 10g R2 RAC on RHEL. As of now, i have 3 redo log files of 50MB size. i have used redo log size advisor by setting fast_start_mttr_target=1800 to check the optimal size of the redologs, it is showing 400MB. Now, i want to increase the size of redo log files. how to increase it?
    If we are supposed to do it on production, how to do?
    I found the following in one of the article....
    "The size of the redo log files can influence performance, because the behavior of the database writer and archiver processes depend on the redo log sizes. Generally, larger redo log files provide better performance, however it must balanced out with the expected recovery time.Undersized log files increase checkpoint activity and increase CPU usage."
    I did not understand the the point however it must balanced out with the expected recovery time in the above given paragraph.
    Can anybody help me?
    Thanks,
    Praveen.

    You dont have to shutdown the database before dropping redo log group but make sure you have atleast two other redo log groups. Also note that you cannot drop active redo log group.
    Here is nice link,
    http://www.idevelopment.info/data/Oracle/DBA_tips/Database_Administration/DBA_34.shtml
    And make sure you test this in test database first. Production should be touched only after you are really comfortable with this procedure.

  • How to increase the limit of open socket sonnections under Windows 2000

    Hello,
    I'm testing a java proxy. On a linux machine the proxy handles about 160 requests per second.
    On a windows machine it only handles about 12 requests per second. On the other hand apache on the same machine can handle 10 times as many requests.
    I think that the amount of open Socket TCP/IP connections available to the java proxy is limited, when I run the program on the windows machine.
    I was wondering where and how I can increase the maximum number of open file descriptors (in my case Socket's) ??
    In linux you have to change the hard limit of the user. How can I increase the number of possible TCP connections available to a java program?
    Fritz

    In your proxy have you implemented the connection keep allive feature.
    I think that your problem is with the owerhead of establishing the connection again and again.
    Normaly a proxy should use the same socket connection to handle all the requests comming from one client.
    And also it should maintane a pool of socket connections to the recently visited web sites and reuse them.
    Becouse every client normaly sends multiple requests to the server rapidly to request pages from same site becouse once a page is downloaded it should download all the related files such as images.
    If you do not keep the connection allive you will slow down the server

  • How to Increase the memory size of a File in the Application Server

    Hello Abaper's
    I have generated a XML file for the data of  internal table (with 10 Records). When i download , i can see the XML file for the Entire 10 Records.
    But , while transferring the XML file to Applicationserver , it's  transferring only upto max 4 Records.I     assume that the memory is insufficient to  allocate 10  Records. Can we Increase the Memory size of the File on Application server. OR,  is there any error in My Source Code.
    Code i used to Transfer the XML File to Application server.
    OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE.
    IF sy-subrc EQ 0.
       LOOP AT it_xmltab INTO wa_xmltab.
           TRANSFER wa_xmltab TO FNAME.
       ENDLOOP.
    ELSE.
      MESSAGE e004(zmsg5) WITH 'File FNAME not opened'.
    ENDIF.
    CLOSE DATASET FNAME.
    Regards
    Jv

    Hi,
    DATA : filename TYPE rlgrap-filename.
    DATA : doc_name TYPE char30.
    DATA : bin_size TYPE i.
    SELECT matnr matkl meins
           FROM mara INTO TABLE it_mara
           UP TO 10 ROWS.
    CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
      EXPORTING
        i_filename           = filename
        i_xml_doc_name       = doc_name
      IMPORTING
        pe_bin_filesize      = bin_size
      TABLES
        i_tab_sap_data       = it_mara         "  contains  10 Records
      CHANGING
        i_tab_converted_data = it_xmltab.
    placing XML File in Appl. Server
    DATA : FNAME(60) VALUE 'xyz_File'.
    DATA : num TYPE i.
    DATA : xmldata(256) TYPE x.
      For Writing The data in Application Server
    OPEN DATASET FNAME FOR OUTPUT IN BINARY MODE. " ENCODING DEFAULT.
    IF sy-subrc EQ 0.
      LOOP AT it_xmltab INTO wa_xmltab.
        TRANSFER wa_xmltab TO FNAME.
      ENDLOOP.
    ELSE.
      MESSAGE e004(zmsg5) WITH 'File FNAME not opened'.
    ENDIF.
    CLOSE DATASET FNAME.
      For Reading The data in Application Server
    OPEN DATASET FNAME FOR INPUT IN BINARY MODE. " ENCODING DEFAULT.
    DO.
      IF sy-subrc EQ 0.
        READ DATASET fname INTO xmldata.
        WRITE :/ xmldata.
        Clear xmldata.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
    CLOSE DATASET FNAME.
    at runtime i can see   
    it_mara  --> contain 10 records
    it_xmltab --> contain 7 lines (Each line size is 255 char). This table have XML format data,  (unknow format , with all numeric 
                        digits)
    it_xmltab is trasferred to application server , but the xml format is generated upto 4 records, and for the remaining records
    the XML format is not generated.
    the XML data in application server file is
    <?xml version="1.0"?><TY_MARA><TY_MARA><MATNR Datatype="C" Length="36">0-BUY1</MATNR><MATKL Datatype="C" Length="18">012</MATKL><MEINS Datatype="C" Length="6">PC
    </MEINS>
    </TY_MARA><TY_MARA><MATNR Datatype="C" Length="36">0-BUY2</MATNR><MATKL Datatype="C" Length="18">012</MATKL><MEINS Datatype="C" Length="6">
    PC </MEINS>
    </TY_MARA><TY_MARA><MATNR Datatype="C" Length="36">000000000000000001</MATNR><MEINS Datatype="C" Length="6">EA</MEINS>
    </TY_MARA><TY_MARA><MATNR Datatype="C" Length="36">000000000000000002</MATNR
    Regards
    JV

  • Cash Journal : How to set the limit for maximum payment of 20000

    Hi Gurus,
    Please tell me how can i set the maximum payment limit of 20000 in cash journal?
    Please revert asap.
    Thank You

    Hi
    Amount Limit
    Use
    You use these functions to define limit values for the FI cash journal; where these limits are reached and exceeded, the user is prompted (in an information dialog box) to run certain activities. The check is always performed in the first local currency of the company code.
    In the countries of the European Union, these functions are used to draw attention to the legal requirement for identifying the payer (money laundering law § 3 para. 1).
    Activities
    Company code:
    You do not have to enter a company code. The entry is then valid for all company codes within a client that use the currency specified as the first local currency.
    Currency:
    Each amount must be specified by the classification of the currency. If you specify a company code, the currency of the company code is entered in the currency field and you cannot change this.
    Date and amount:
    The amount limits are defined time-dependent ("Valid From").
    In addition to the above
    Input your company code,Currency,Valid from and the amount limit
    Good Luck
    Hari

  • How to increase the limit of how many emails we can send at once for a buisiness

    I want to send regular catalogs out to my customers (approx 600 email addresses at the moment) and I believe the maximum limit is 200 per hour or something right now. I am unsure if everyone is getting my e-mails and want to know either if all the email will eventually go through or if there is a more effective way to do this? I've tried the mail merge but that isn't working for me.

    Thunderbird does not set limits. Your email provider does. Ask them.

  • How to increase the limit of 5 recently bookmarked folders

    Hi, I saw this issue was raised several times over many years, but no solution as yet. When one adds a bookmark, firefox shows a very useful menu of the most recently added folders in the bookmark tree. It shows the last 5, but it would be wildly more useful if it could be tweaked to show 10 or 20.
    Its not an about:config option due to a design decision by Mozilla, as far as I found out. And none of the bookmark addons do exactly that. There is a patch here,
    "Makes the number of recent bookmarks folder to be an about:config option. "
    https://bugzilla.mozilla.org/attachment.cgi?id=571412&action=edit
    from the thread:
    https://bugzilla.mozilla.org/show_bug.cgi?id=482027
    But I don't know how can I use this piece of code? does it require recompliation of Firefox? I use Version 27 on Windows 7, 64 Bit. Will this mean I will have to recompile and re-integrate the fix every time I upgrade FF? thanks

    Thank you, but it doesn't seem to work - I don't see any faint arrows and the expanded bookmark window that comes with this addon still only shows 5 most recently added folders (attached immage to clarify - I want a larger list of recently added folders, not an expanded bookmark tree)

  • How to Increase the # of Recently Opened Files in DW CS6 ???

    Can anyone please give a detailed instruction on how to increase the number of Recently Opened files in Dreamweaver CS6? I have read the forums everywhere and do not see a solution here that works. For me there is no: Menus/MM/File_RecentFiles.htm
    I mean I have a "Menus" directory but no "MM" directory inside that... also, if I create one... I still need a sample "File_RecentFiles.htm" to copy. Or maybe someone knows another solution?

    I don't have DWCS6, just DWCS4 and DWCC. When I go to Program Files(x86) > Adobe >  Adobe Dreamweaver CC (or Dreamweaver CS4) > configuration > Menus > MM > and then open the file named "File_RecentFiles.htm" at either location, this is the code...
    <!-- MENU-LOCATION=NONE -->
    <html xmlns:MMString="http://www.macromedia.com/schemes/data/string/">
    <HEAD>
    <!-- Copyright 2000, 2001, 2002, 2003, 2004, 2005 Macromedia, Inc. All rights reserved. -->
    <TITLE><MMString:loadString id="Menus/MM/File_RecentFiles/title" /></TITLE>
    <SCRIPT LANGUAGE="javascript" SRC="../../Shared/MM/Scripts/CMN/string.js"></SCRIPT>
    <SCRIPT LANGUAGE="javascript" SRC="File_RecentFiles.js"></SCRIPT>
    <SCRIPT LANGUAGE="javascript">
    <!--
    //--------------- LOCALIZEABLE GLOBALS---------------
    var MENU_RecentFile  = dw.loadString('Menus/MM/File_RecentFiles/MENU_RecentFile');
    //--------------- END LOCALIZEABLE   ---------------
    // -->  
    </SCRIPT>
    </HEAD>
    <BODY>
    </BODY>
    </HTML>
    EDIT: It appears you should definitely have this file, unless something is wrong with your installation, or perhaps you are in the wrong directory?

  • How to increase the the max limit column in pivot view in BIEE 11G?

    Hi Experts,
    How to increase the the max limit column in pivot view in BIEE 11G?
    When the number of column exceed 256 in pivot view, it will generate the following error message as below:
    Exceeded configured maximum number of allowed output prompts, sections, rows, or columns.
    Error Details
    Error Codes: IRVLJWTA:OI2DL65P
    Location: saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool.socketrpcserver, saw.threads
    SQL Issued: 13678~vid1ptgt0v5ubh39gesnauuhl6
    For example:
    ----------------Day
    Country-----20120101---20120102---..........20121231
    China--------10000---------20000----......

    Try increasing the Max Rows in Instanceconfig.xml
    Path:-Middleware\instances\instance1\bifoundation\OracleBIPresentationServices\instanceconfig.xml
    <ServerInstance>
    <Views>
    <Pivot>
    <MaxVisibleColumns>300</MaxVisibleColumns>
    <MaxVisiblePages>1000</MaxVisiblePages>
    <MaxVisibleRows>500</MaxVisibleRows>
    <MaxVisibleSections>25</MaxVisibleSections>
    <DefaultRowsDisplayed>30</DefaultRowsDisplayed>
    </Pivot>
    </Views>
    </ServerInstance>
    Try adding this in the config file and restart the services.
    Mark as correct if it is helpful.
    Thanks.

  • How to increase the per-process file descriptor limit for JDBC connection 15

    If I need JDBC connection more that 15, the only solution is increase the per-process file descriptor limit. But how to increase this limit? modify the oracle server or JDBC software?
    I'm using JDBC thin driver connect to Oracle 806 server.
    From JDBC faq:
    Is there any limit on number of connections for jdbc?
    No. As such JDBC drivers doesn't have any scalability restrictions by themselves.
    It may be it restricted by the no of 'processes' (in the init.ora file) on the server. However, now-a-days we do get questions that even when the no of processes is 30, we are not able to open more than 16 active JDBC-OCI connections when the JDK is running in the default (green) thread model. This is because the no. of per-process file descriptor limit exceeded. It is important to note that depending on whether you are using OCI or THIN, or Green Vs Native, a JDBC sql connection can consume any where from 1-4 file descriptors. The solution is to increase the per-process file descriptor limit.
    null

    maybe it is OS issue, but the suggestion solution is from Oracle document. However, it is not provide a clear enough solution, just state "The solution is to increase the per-process file descriptor limit"
    Now I know the solution, but not know how to increase it.....
    pls help.

  • How can I increase the limit of iTunes Genius Mixes?

    How come my macbook is limited to 6 Genius Mixes, while I've seen screenshots of people having about 12 mixes available? is there anything I can do to increase the limit?

    Twelve is normal. You might try turning Genius off and back on to refresh it and see if it will then give you more. If you have content only from a very few genres, though, it's possible it can't find enough variety to generate more than six. Or if you have a lot of unusual tracks, particularly ones not sold in the iTunes Store, there may not be Genius data available on which iTunes can base a mix.
    Regards.

  • How to increase the attachment size of a portal

    Hi,
    We have a portal developed using JSP.
    We have an option for attaching files. Now the maximum limit is only 5 MB. So we thought of using FTP so that we can increase the attachment limit. But we are not able to attach files more than 1 MB.
    Could you please help us in resolving this. Any idea how to increase the attachment size limit?
    Thanks in advance

    Hi,
    See what Patrick Yee has posted.
    how to create own page format in smartforms immmedia
    Svetlin

Maybe you are looking for

  • Intermittent errors when editing PP in Captivate 4

    This has been driving me crazy, and I have looked far and wide for the answer, hopefully I haven't overlooked it anywhere. I imported my PP to C4 as a linked file, and it worked fine, I was able to edit it with no issues. A few days later, I had to m

  • 20" or 23" Cinema Display contrast ratio and models

    I am searching for a used Cinema Display, either 20 or 23". I want to ensure that I am getting a recent model, and I have seen mention of older 400:1 units, and newer generation 700:1 units. How can I tell what I'm looking at when I am searching? Are

  • Code and core tables in different schemas

    Hi, My db version : Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production I would like to understand, the pros and cons of the following situation: We have a single application. The db design for this application has 44 tables

  • I have photoshop elements 10 on old computer

    Can I download or upgrade my photoshop elements 10 that I had on my old computer?

  • Automatic Update causing errors

    I installed an automatic update to what I thought was Adobe reader and now Adobe Pro gives me an error "A serious error has been detected and Abodbe Acrobat 8.1.0 Professional cannot contineu.  Please reainstall the application and try again" any tim