<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)">
Here's where I've gotten.&nbsp; If anyone has any</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
clarifications or suggestions, please let me&nbsp;</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
know!</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)">
pstat -f shows 164 / 3404 open files.<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
3404 - 164 = 3240</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)">
File # 3248 fails with errno 23.</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)">
On a later test</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
pstat shows 166/3404 open files</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
3404 -166 = 3238</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)">
File # 3246 fails with errno 23.<br>
<br>
Both times these numbers are off by 8.</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 haven't figured out why exactly fstat is 3 greater than pstat -f,&nbsp;</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
nor <span style="font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255); display: inline !important">
provably<span>&nbsp;</span></span>why there are 8 extra files than expected.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
&nbsp;&nbsp;</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
My hunch about fstat vs pstat difference (3):</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
fstat VS pstat has something to do with</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
&nbsp;stderr, stdout, and stdin</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)">
My theory about the pstat vs open files difference (8):</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;">There are 7 kqueue filetypes in pstat -f.&nbsp;&nbsp;</span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
If it fails on #3248 (in the first example),&nbsp;</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
that means 3247 succeeded.</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; background-color: rgba(0, 0, 0, 0);">&nbsp; &nbsp; &nbsp; &nbsp; 3247 + 164 = 3,411, which is 7 over 3404</span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I suspect there's something funky with these kqueue files.</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)">
<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)">
<br>
</div>
<div id="appendonsend"></div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> cs631apue-bounces@lists.stevens.edu &lt;cs631apue-bounces@lists.stevens.edu&gt; on behalf of Jan Schaumann &lt;jschauma@stevens.edu&gt;<br>
<b>Sent:</b> Wednesday, September 16, 2020 8:49 AM<br>
<b>To:</b> cs631apue@lists.stevens.edu &lt;cs631apue@lists.stevens.edu&gt;<br>
<b>Subject:</b> Re: [cs631apue] Openmax.c fails earlier than expected</font>
<div>&nbsp;</div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">Charles Magyar IV &lt;cmagyar@stevens.edu&gt; wrote:<br>
&gt; If errno == EMFILE, the errno = 24.&nbsp; &quot;Too many open files&quot; according to the man page of errno.<br>
&gt; <br>
&gt; In the else block, errno equals 23 during my run.<br>
&gt; This is ENFILE, and means &quot;Too many open files in system.<br>
&gt;&nbsp; Maximum number of file descriptors allowable on the system has been reached and a request<br>
&gt;&nbsp; for an open cannot be satistfied until at least one has been closed.&quot;<br>
&gt; <br>
&gt; So it turns out that the entire system is simply out of space.<br>
<br>
Correct.&nbsp; That is, there's a difference between _a<br>
process_ having reached the limit of how many files it<br>
can open and _the whole system_ having reached its<br>
limit.<br>
<br>
Normally, the limit for a process is smaller than that<br>
of the entire system, but we bumped it to 'unlimited',<br>
meaning we set the per-process limit to be equal to<br>
that of the system-wide limit.<br>
<br>
Since nowe we're talking about the system wide limit,<br>
we are no longer just competing with ourselves, but<br>
with all processes on the system.&nbsp; In other words, any<br>
file open by any other process reduces the number of<br>
files our process can open.<br>
<br>
So the number of files we can open before encountering<br>
ENFILE should be:<br>
<br>
ourfiles = number of files this process can open <br>
otherfiles = number of files open by any other process<br>
max = system wide limit, i.e., 3404 in this case<br>
<br>
ourfiles = max - otherfiles<br>
<br>
&gt; In another test, I ran<br>
&gt;&nbsp; &gt;&nbsp; fstat | wc -l<br>
&gt; &gt; 249<br>
<br>
fstat(1) shows us the open _file descriptors_, but the<br>
limit is on entries in the file table.&nbsp; That is, if a<br>
process has multiple file descriptors pointing to the<br>
same file table entry (such as e.g., duplicated file<br>
descriptors such as when a process has stdin,<br>
stdout, and stderr all connected to terminal), only<br>
the one file table entry counts towards the limit.<br>
<br>
You can use the pstat(1) command with the '-f' flag to<br>
show you the collated mapping; the output includes a<br>
column &quot;CNT&quot; that shows you how many&nbsp; references to<br>
the givenf ile table entry there are.<br>
<br>
You can also use 'fstat -A' to get the relevant object<br>
address, and correlate it with the output of 'pstat'.<br>
For example:<br>
<br>
$ fstat -A | sort -k1,1 | grep pts/0<br>
ffffcf1371e74040 jschauma sh&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1995&nbsp;&nbsp;&nbsp; 0 /dev/pts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 crw--w----&nbsp;&nbsp; pts/0 rw<br>
ffffcf1371e74040 jschauma sh&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1995&nbsp;&nbsp;&nbsp; 1 /dev/pts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 crw--w----&nbsp;&nbsp; pts/0 rw<br>
ffffcf1371e74040 jschauma sh&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1995&nbsp;&nbsp;&nbsp; 2 /dev/pts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 crw--w----&nbsp;&nbsp; pts/0 rw<br>
...<br>
$ fstat -A | sort -k1,1 | grep -c pts/0<br>
17<br>
$ $ pstat -f | grep ffffcf1371e74040<br>
ffffcf1371e74040 file&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RW&nbsp;&nbsp; 14&nbsp;&nbsp;&nbsp; 0 ffffcf136cc22970&nbsp;&nbsp; 0&nbsp; 372401<br>
<br>
That is, pstat(1) shows us that there are 14<br>
references to /dev/pts/0 (our pseudo-terminal).<br>
<br>
(But fstat(1) showed us 17 - can you find out why<br>
'pstat' showed 3 fewer?)<br>
<br>
Anyway, try to run the same command and compare to the<br>
output of 'pstat -f'.&nbsp; Does that match the number of<br>
files you are then able to open?<br>
<br>
-Jan<br>
_______________________________________________<br>
cs631apue mailing list<br>
cs631apue@lists.stevens.edu<br>
<a href="https://lists.stevens.edu/mailman/listinfo/cs631apue">https://lists.stevens.edu/mailman/listinfo/cs631apue</a><br>
</div>
</span></font></div>
</body>
</html>