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

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_DGRAM)
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

socket and os.system 4

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top