<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hello all,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I changed openmax.c openFiles(int num) to print out what # iteration of the loop it is in when open fails (and NOT because of EMFILE limit).</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
The code is included at the end of this e-mail.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I change the limit to unlimited, and the program starts to throw issues at file # 3249. I had 8 files already open. </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
With 8 files open, I would expect it to fail at 3396.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Also, the last line of output is File # 3405 which fails due to "too many files" rather than "due to limit."</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">The number 3405 makes sense because the function is called with the num parameter of 3404, </span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
and the loop goes up until num+1, but it's interesting that it doesn't generate the EMFILE errno.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255); display: inline !important">Attached is a short video illustrating my results. </span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
void
<div>openFiles(int num) {</div>
<div> struct stat stats;</div>
<div> int count = 0;</div>
<div> int fd;</div>
<div><br>
</div>
<div> for (int i = 0; i < num; i++) {</div>
<div> if (fstat(i, &stats) == 0) {</div>
<div> printf("Fd #%d is open.\n", i);</div>
<div> count++;</div>
<div> }</div>
<div> }</div>
<div> printf("Currently open files: %d\n", count);</div>
<div><br>
</div>
<div> for (int i = count; i <= num + 1; i++) {</div>
<div> if ((fd = open("/dev/null", O_RDONLY)) < 0) {</div>
<div> if (errno == EMFILE) {</div>
<div> printf("Opened %d additional files, then failed due to limit.\n", i - count);</div>
<div> break;</div>
<div> } else {</div>
<div> <span style="background-color: rgb(255, 255, 0);"> fprintf(stdout, "File # %d err\n",i);</span></div>
<div> fprintf(stderr, "Unable to open '/dev/null': %s\n",</div>
<div> strerror(errno));</div>
<div> }</div>
<div> }</div>
<div> }</div>
}<br>
</div>
</body>
</html>