Hey Evry1
Am very excited right now coz i got a dvd for sarge with the pcquest this
month and just finishd installling it. Kudos to the PCQUEST...its really a
beauty. 1 DVD - exclusive for SARGE. Thanks to Master Sameer Thahir for
various tips durin the installation process,what can I do without u.
Anyway, thought i wld share my views on the zombie process from the kernel
perspctive.
Lets tweak Justin's program to make a slight change. Allow the parent to
terminate well b4 the child. Now, the child finishes its job and becomes a
zombie process.
When I say tht the child becomes a zombie I mean tht all the objects held by
the child are freed and the child's state ( evry process has a state field
in the structure (task_struct) in kernel tht holds info abt tht process- 1.7
kb in 32 bit machine) is changed to TASK_ZOMBIE.Its kernel stack ,containing
its task_struct etc are maintained to provide info to its parents. The
zombie processes are never schduled so they jst remain in memory until the
parent terminates them.
Now usually, its the responsibility of the parent to deallocate the
task_struct and terminate the child process. But in our case, the parent had
already terminated.So the child remains a zombie..using up our valuable
resources..
Sad! Dont Worry.The linux kernel has a marvellous mechanism to solve this
problem. The kernel reparents the child.ie. it tries to find another parent
for the orphan zombie process from the current thread group.If tht
fails..the child will b adopted by the init process.
The init process routinely calles wait() on its children ,cleaning up any
zombie assigned to it.
Thus zombies die no mattr what. Either their parents kill them..or if their
parents are dead,init murders them.
To kill the zombie child, its parent has to call wait().So if u want to
kill a zombie, u will hav to be its parent. So heres a idea. I dnt knw how
pratical or possibl this is:
start:
repeat till no more zombies remain.
find one zombie process.
set its parent pointer to point to ur process(access its
task_struct))
call wait()
stop
This cld b possibl if u r inside the kernel. I am not sure abt this
scenario outside the kernel.
But why go thru all this trouble if the kernel itself handles this for
you?????
I am not including the kernel code for this. Its prtty intrsting and easy to
undrstnd.Those intrstd may refer to any books on kernel devlopmnt. For 2.6.x
," Linux Kernel Devlopment" by Robert Love is a splendid book.
Please correct me if I am wrong..or if thrs anythin else ..do mail in .
TKE CRE
regrds
Hashir N A
-------------------------------------------------------------------------
Do What U Must not Must U what. * _ *
-------------------------------------------------------------------------
>From: justin joseph <[EMAIL PROTECTED]>
>Reply-To: "This List discusses GNU/Linux & GNU,GPL
Software" <[email protected]>
>To: [email protected]
>Subject: [Mailinglist] more on Zombie
>Date: Fri, 3 Dec 2004 23:17:14 -0800 (PST)
>
>hi all,
>
>thought to explain why a zombie cannot be killed.
>
>main()
>{
> int pid;
>
> pid = fork(); /*the integer pid now holds the return value of
> fork, fork returns the child process id in
> parent and 0 in the child process */
>
> if(pid == 0) { /*the body of the if-statement is executed */
> sleep(1); /* only in the child*/
> exit();
> }
> sleep(30); /*the parent, straight away goes to sleep*/
>}
>
>the above program is a very simple one, all ought to understand it.
>
>fork is a system call used to generate child process. so once we call
fork,
>we get two process, one the parent and the other the child.
> |
> |
> |
> |
> fork()
> / \
> / \
> / \
> / \
> parent child
>
>fork returns twice, once in parent and once in child. In the parent
fork returns
>the process id(PID) of the child, and in the child it returns 0.
>
>
>so the body of the if-statement is executed in the child process only
the child process sleeps for one second and then exits ie terminates. the
parent process goes on to sleep for thirty more seconds. please note that
the child process was made to sleep for one second to make sure that the
parent is sleeping when the child exit()'s.
>
>
>and then by definition of a zombie process, the child should have become
a zombie process
>because its exit status is not known by the parent, because the
'irresponsible' parent was
>sleeping when its child died.
>
>
>the below few lines are the last lines of the output of 'ps -l a'
command.
>
>
>100 S 0 412 408 0 75 0 - 554 11d2b8 pts/1
0:00 /bin/bash
>000 S 0 417 261 0 72 0 - 309 12228a tty1
0:00 ./a.out
>044 Z 0 418 417 0 72 0 - 0 11ce8a tty1
0:00 [a.out <defunct>]
>000 R 0 420 412 0 77 0 - 669 - pts/1
0:00 ps -l a
>
>and can we see that the parent with pid number 417 is sleeping and the
child with pid 418 is now a defunct process with status shown as Z, meaning
Zombie process( make sure you switch terminal and give command 'ps -l a'
before 30 thirty seconds to view this behaviour).
>
>understand why trying to kill a Zombie process just wont work. simply
because its allready dead.
>
>once the parent wakes up after 30 seconds it gets the status of the
child process and the zombie child vanishes( 'ps -a l' after the parent has
terminated to see this).
>
>another way to get rid of the zombie is to kill the parent process, in
this case 'kill -9 417' will kill the parent and take out the zombie as
well, 'ps -a l' after killing the parent to see that the zombie has
vanished.
>
>please reply to the post if i have made a mistake in grasping the
concept and/or if things are out of context and/or if there is something
more to be explained. also please explain if Zombies can be 'eliminated' in
any other way, i remember to have seen code to eliminate
>all the zombie processes. is this possible.
>
>justin
>
>
>
>
>
>---------------------------------
>Do you Yahoo!?
> The all-new My Yahoo! Get yours free!
>_______________________________________________
>Mailinglist mailing list
>[email protected]
>http://mail.ilug-cochin.org/mailman/listinfo/mailinglist_ilug-cochin.org