Changing maximum number of open files for your running process lazarus / 32-Linux ---------------------------------------------------------------------- Molochnik · 2024-01-01 22:55 Is it possible to change the maximum number of open files for your currently running process? I tried different approaches but failed Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    if RunCommand('/bin/bash',['-c','ps -C testapp -o pid='],s) then     writeln(s);// finding your currently running pid  if RunCommand('/bin/bash',['-c','prlimit --pid ' + s.trim + ' --nofile=1024:1024'],s) then     writeln(s);// changing max number of the open files to 1024 via prlimit, RunCommand fails  if RunCommand('/bin/bash',['-c','ulimit -Sn 1024'],s) then     writeln(s);// changing max number of the open files to 1024 via ulimit, no error and no result   if RunCommand('/bin/bash',['-c','ulimit -Sn'],s) then     writeln(s);// shows the maximum number of open files, works fine, the return value is always the same ---------------------------------------------------------------------- Kays · 2024-01-04 02:18 Quote from: Molochnik on January 01, 2024, 11:55:32 pmIs it possible to change the maximum number of open files for your currently running process?Yes.Quote from: Molochnik on January 01, 2024, 11:55:32 pmI tried different approaches but failedThe resource limits apply to the current process. RunCommand spawns a new process so any changes do not propagate to the parent process. You will need to utilize the setrlimit system call directly.Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program fileHoarder(input, output, stdErr);{$typedAddress on}uses        errors, math, baseUnix;const        minimumMaximumNumberOfFiles = 19479;var        limit: tRLimit;begin           { What limits does the current process have? }        case fpGetRLimit(rLimit_noFile, @limit) of                { failure }                -1:                begin                        pError('Could not obtain maximum open files resource limits',                                fpGetErrno);                      halt;                end;                { success }               0: ;        end;                { Current soft limit below the minimum maximum? }        if limit.rLim_cur < minimumMaximumNumberOfFiles then        begin                { Raise soft limit. The hard limit requires extra privileges. }              limit.rLim_cur := minimumMaximumNumberOfFiles;                { Soft limit argument may not exceed the hard limit argument. }              limit.rLim_max := max(limit.rLim_max, limit.rLim_cur);                              case fpSetRLimit(rLimit_noFile, @limit) of                      { failure }                        -1:                      begin                                writeLn(stdErr, 'Error: Could not raise maximum open files resource limit.');                              case fpGetErrno of                                        eSYsEInval:                                        begin                                              writeLn(stdErr, 'A programming mistake caused the invalid parameter',                                                      'tRLimit[rLim_cur: ', limit.rLim_cur:1,                                                      '; rLim_max: ', limit.rLim_max:1, '].');                                        end;                                      eSysEPerm:                                      begin                                                writeLn(stdErr, 'The raised limits exceed the system’s hard limits.');                                        end;                              end;                                halt;                      end;                        { success }                       0: ;                end;        end;                { Optional: Let’s verify our result. }        case fpGetRLimit(rLimit_noFile, @limit) of                { success }                 0:              begin                        writeLn('I can have up to ', limit.rLim_cur:1, ' open files.');                end;        end;end. ---------------------------------------------------------------------- Molochnik · 2024-01-04 16:30 Kays That works perfect! Thank you very much!