subprocess (spawned by os.system) inherits open TCP/UDP/IP port

alf ask at me
Fri Jul 20 15:15:39 CEST 2007

Jean-Paul Calderone wrote:

> You can avoid this, if you like.  Set FD_CLOEXEC on the socket after you
> open it, before you call os.system:
>  old = fcntl.fcntl(s.fileno(), fcntl.F_GETFD)
>  fcntl.fcntl(s.fileno(), fcntl.F_SETFD, old | fcntl.FD_CLOEXEC)

thx for responding (I was about to send the question to twisted mailing 
list too ;-).

still would like to find out why it is happening (now FD_CLOEXEC 
narrowed may yahooing/googling searches). While realize that file 
descriptors are shared by forked processes it is still weird why the 
port moves to the child process once parent gets killed. what it the 
parent got multiple subprocesses.

Plus it is kind of unintuitive os.system does not protect from such 
behavoir which is for me more an equivalent of like issuing a ne 
wcommand/ starting a process from the shell.



More information about the Python-list mailing list