os.fork on linux defunct

R

Ray

I'm running python 2.4 on linux. I use python os.fork run tcpdump, but
after I kill the forked process (tcpdump) in linux it shows defunct

here is the code:

#!/usr/bin/python
import time, os
class Test:
def fork(self):
self.pid=os.fork()
if self.pid=0:
args=['tcpdump', '-i', 'eth0', 'port', '80' '']
os.execl("/usr/sbin/tcpdump", *args)
os._exit(0)
def kill(self):
os.kill(self.pid, 15)
if __name__=='__main__':
while True:
test=Test()
test.fork()
time.sleep(2)
test.kill()
time.sleep(30)

after I call kill() it will kill tcpdump (capture will stop) but on
linux, ps shows tcpdump as defunct process
what am I missing?

thanks for any help.
 
R

Ray

I'm running python 2.4 on linux. I use python os.fork run tcpdump, but
after I kill the forked process (tcpdump) in linux it shows defunct

here is the code:

#!/usr/bin/python
import time, os
class Test:
    def fork(self):
        self.pid=os.fork()
        if self.pid=0:
            args=['tcpdump', '-i', 'eth0', 'port', '80' '']
            os.execl("/usr/sbin/tcpdump", *args)
            os._exit(0)
    def kill(self):
        os.kill(self.pid, 15)
if __name__=='__main__':
    while True:
        test=Test()
        test.fork()
        time.sleep(2)
        test.kill()
        time.sleep(30)

after I call kill() it will kill tcpdump (capture will stop) but on
linux, ps shows tcpdump as defunct process
what am I missing?

thanks for any help.

I think I found it. need to call os.wait()
 
C

Cameron Simpson

| > I'm running python 2.4 on linux. I use python os.fork run tcpdump, but
| > after I kill the forked process (tcpdump) in linux it shows defunct
[...]
| > after I call kill() it will kill tcpdump (capture will stop) but on
| > linux, ps shows tcpdump as defunct process
| > what am I missing?
| > thanks for any help.
|
| I think I found it. need to call os.wait()

Yep. "defunct" == "zombie". See:

http://code.activestate.com/lists/python-list/580569/

Cheers,
--
Cameron Simpson <[email protected]> DoD#743
http://www.cskk.ezoshosting.com/cs/

Talk is the bastard redheaded stepchild of email and the telephone.
- Geoff Miller, (e-mail address removed)
 
L

Lawrence D'Oliveiro

In message
Ray said:
I think I found it. need to call os.wait()

The rule on Unix/Linux systems is: “always remember to gobble your zombie
childrenâ€.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top