Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 23rd, 2004, 09:06 AM
winwin winwin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 21 winwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Zombi process

Arg! Help! My process table is full of undead zombi threads!
Seems my script doesn't take care of his serious child problem!

How can you clean a child thread to prevent it from becoming a zombi thread ?
(how can you use the os.kill command, if it is the solution...)

Thanks,
(BTW when i said full of zombies it looks more like 1 to 2 thousand zombies... so i'd prefer taking care of the problem)

Reply With Quote
  #2  
Old June 23rd, 2004, 02:11 PM
ryankask ryankask is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Posts: 52 ryankask User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 44 sec
Reputation Power: 7
Maybe import the os module, run loop through every process you want to kill and run a command os.system('kill -9', x)? I'm new at all this so don't kill me if that is totally irrelevant.

Reply With Quote
  #3  
Old June 23rd, 2004, 03:33 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,226 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 23 h 35 m 17 sec
Reputation Power: 263
Are these threads created through the Python thread/threading modules, or are they child processes created with os.fork?

Either way the thread or process should terminate naturally unless they are stuck in an infinite loop or blocked waiting for some resource to be released.

Dave - The Developers' Coach

Reply With Quote
  #4  
Old June 24th, 2004, 02:17 AM
winwin winwin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 21 winwin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well the thing is that the kill -9 command does not work, I tried it... once the processes are written with the "defunct" mention next to them they are unkillable because they don't really exist any more i think....

Theses processes were created with the thread module, but they should end, there is no infinit loops in them, and they don't seem to take computing time either, so it looks as if they are not running.

Well in fact it is a little more complicated, I start a thread and in the thread i use an os.spawnv (this does an automatic fork I think?) to start another script, and it is that script that zombifies. (Should there be a return None at the end of all functions? because i tried to put a sys.exit() to be sure it exited but it still stays there as a zombi, so i'm thinking that the parent process -the thread- has to clean up by its self...)

Reply With Quote
  #5  
Old June 24th, 2004, 03:07 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,226 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 23 h 35 m 17 sec
Reputation Power: 263
My understanding of sys.exit is that if called in the main thread it will kill all the other threads, but if called in a child thread it will only kill off that thread. I may be wrong though. I don't know if that is related to the problem you are having.

Some more questions:

* are the spawned programs also written in Python?

* is there any way to debug them, e.g. by putting in trace statements so that you can see what they are blocking on?

Dave - The Developers' Coach

Reply With Quote
  #6  
Old June 24th, 2004, 05:44 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
I did a few experiments and I think you have two options:
1. Only spawn the child processes in the main thread (why do you need to spawn them in a child thread, perhaps you only need threads for monitoring if at all?). This will allow the child processes to respond to the os.kill.

2. If you must use threads then you need to signal the child process program to terminate somehow and then os.wait() for the child process to finish. But os.kill is ignored! Perhaps you can signal the child app using sockets or pipes.

This code starts two processes and then kills them:
Code:
import os
import signal
import time

procs = []

for n in range(2): 
    procs.append(os.spawnvp(os.P_NOWAIT, "ping", ["ping", "127.0.0.1"]))

print procs
time.sleep(5)
for n in procs: 
    print n
    os.kill(n, signal.SIGINT)



This code tries to do the same thing but fails.
The kill signal is ignored.
Code:
import threading
import os
import signal
import time

procs = []
class Worker(threading.Thread): 
    def run(self): 
	procs.append(os.spawnvp(os.P_NOWAIT, "ping", ["ping", "127.0.0.1"]))

for n in range(2): 
    a = Worker()
    a.start()

print procs
time.sleep(5)
for n in procs: 
    print n
    os.kill(n, signal.SIGINT)


When the shell process from which the python program was run is killed the child processes are stopped but you are left with two do nothing zombies.

grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #7  
Old June 24th, 2004, 05:53 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Actually, the processes I generarted are reported as Sleeping and not Zombified.

Not sure if this will help.

These processes can be killed with kill -9 PID.

Last edited by Grim Archon : June 24th, 2004 at 06:01 AM. Reason: update on kill

Reply With Quote
  #8  
Old June 24th, 2004, 06:16 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
Minor changes...
Code:
	procs.append(os.spawnvp(os.P_NOWAIT,"ping",["ping","127.0.0.1"]))
	os.waitpid(procs[-1],0)


Code:
for n in procs:
    print n
    os.system("kill -9 %s"%n)
print "waiting for the threads to finish"
for n in range(2):
    wt[n].join(5.0)

Worked.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Zombi process


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT