From: Ray on
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.

From: Ray on
On Jul 30, 6:03 pm, Ray <rui.va...(a)gmail.com> wrote:
> 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()

From: Lawrence D'Oliveiro on
In message
<77a879cc-94ab-4e2a-a4af-a6945a5b8e9d(a)q16g2000prf.googlegroups.com>, Ray
wrote:

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

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