<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Mar 11, 2011, at 3:26 , Eric Norum wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">The document at <a href="http://pubs.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html">http://pubs.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html</a><span class="Apple-converted-space"> </span>implies that they really are supposed to be constants:<div><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; "><br></span></div><div><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; ">The following symbolic constants shall be defined for file streams:</span></div><div><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; "><dl compact=""><dt>STDERR_FILENO</dt><dd>File number of <i>stderr</i>; 2.</dd><dt>STDIN_FILENO</dt><dd>File number of <i>stdin</i>; 0.</dd><dt>STDOUT_FILENO</dt><dd>File number of <i>stdout</i>; 1.</dd></dl></span><div><br></div><div>but I agree that that is rather counterintuitive.</div><br class="Apple-interchange-newline"></div></span></blockquote><span class="Apple-style-span" style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">Am I correct that threads are started with the streams stdin, stdout, and stderr set to files 0, 1, and 2, and don't inherit the file descriptors that the parent thread may have redirected them to?  Is that dictated by any standard?</span></font></span><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">I think it would make more sense if stdin, stdout, and stderr are always files 0, 1, and 2, that the underlying files are switched at context switch time, and that threads inherit whatever underlying files the creating thread may have dup'd them to.  Next in line would be to inherit the parent file descriptors.</span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">Does anyone know about what the standards say about:</span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">- stdin, stdout, stderr,</span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">- file descriptors 0, 1, 2,</span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">- STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO</span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">and how this should play with pthreads? I haven't had much luck figuring it out.</span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div style="font-family: monospace; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">Eric's earlier pointed-out-reference that STDIN_FILENO is by definition 0 implies to me that the way things are is at least confusing.</span></font></div><div><br></div></div>

<br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">Peter<br>-----------------<br>Peter Dufault<br>HD Associates, Inc.      Software and System Engineering</span>
</div>
<br></body></html>