system(3) && open file descriptors

Matthias Apitz guru at unixarea.de
Wed Apr 30 04:41:53 UTC 2014


El día Tuesday, April 29, 2014 a las 02:41:22PM -0700, Charles Swiger escribió:

> Hi--
> 
> On Apr 29, 2014, at 11:43 AM, Matthias Apitz <guru at unixarea.de> wrote:
> > It seems that the proc started by the C library call system(3), as
> > /bin/sh -c string
> > owns the same set of open file descriptors as its calling proc. Is this
> > somewhere documented as a feature? 'man system" does not say anything
> > about, while 'man fork' does.
> 
> At least my version of system(3) says that it invokes fork(2) and checks
> the exit status of the shell via waitpid(2).  That plus listing fork(2)
> in SEE ALSO section seems to be enough of a pointer to the detailed
> behavior....

Hi,
Ofc it must use fork(2), but it *could* as well close all fd before
execv(2). IMHO it should do this for all fd > 2, at least the man page
should mention the fact that it does not.

	matthia
-- 
Matthias Apitz               |  /"\   ASCII Ribbon Campaign:
E-mail: guru at unixarea.de     |  \ /   - No HTML/RTF in E-mail
WWW: http://www.unixarea.de/ |   X    - No proprietary attachments
phone: +49-170-4527211       |  / \   - Respect for open standards
                             | en.wikipedia.org/wiki/ASCII_Ribbon_Campaign


More information about the freebsd-questions mailing list