471,354 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

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

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
0 900

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Stewart Midwinter | last post: by
3 posts views Thread by George Sakkis | last post: by
15 posts views Thread by Thomas Dybdahl Ahle | last post: by
12 posts views Thread by Eric_Dexter | last post: by
1 post views Thread by Mrown | last post: by
1 post views Thread by | last post: by
25 posts views Thread by Jeremy Banks | last post: by
3 posts views Thread by Thomas Jansson | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.