By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

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

P: n/a
alf

Hi,

I need a help with explaining following behavior. Although it is not
python issue per say, python helped me to write sample programs and
originally I encountered the issue using python software. So let's
assume we have two following programs:

[myhost] ~cat ss.py
import socket
UDPSock=socket.socket(socket.AF_INET,socket.SOCK_D GRAM)
UDPSock.bind(("",12345))
import os
os.system('python cc.py')

[myhost] ~cat cc.py
import time
time.sleep(2036)

then I start master one, do ctrl-Z and bg.

[myhost] ~python ss.py

Suspended
[myhost] ~bg
[1] python ss.py &
[myhost] ~ps
UID PID PPID C STIME TTY TIME CMD
myuser00 3192 3189 0 14:57 pts/0 00:00:00 -tcsh
myuser00 3247 3192 0 14:57 pts/0 00:00:00 python ss.py
myuser00 3248 3247 0 14:57 pts/0 00:00:00 python cc.py

[myhost] ~netstat -uanp |grep 12345
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
udp 0 0 0.0.0.0:12345 0.0.0.0:*
3247/python

As expected netstat indicates process 3247 having port allocated. Then I
kill the master process and interestingly the child inherits the port open.
[myhost] ~kill 3247
[myhost] ~netstat -uanp | grep 12345
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
udp 0 0 0.0.0.0:12345 0.0.0.0:*
3248/python
[1] + Terminated python ss.py

Why it is happening? I know that os.system uses fork, but still this is
something unexpected.
Thx, Alf

Jul 20 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.