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

Hrvoje Niksic hniksic at
Fri Jul 20 17:17:12 CEST 2007

alf <ask at me> writes:

> 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.

Netstat probably shows only one of the processes that hold to the
port, possibly the one with the lowest PID (the parent).

> 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.

It is considered a feature that fork/exec'ed programs inherit file
descriptors -- that's how stdin and stdout get inherited all the time.
It doesn't occur often with network connections because shells rarely
have reason to open them.

More information about the Python-list mailing list