Home > Archive > Tcl > May 2004 > Why does "kill [pid $fd]" makes <defunct> ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Why does "kill [pid $fd]" makes <defunct> ?
|
|
| Hao Xu 2004-05-18, 10:32 pm |
| Hello everyone!
In my gui written by tcltk, I open pipelines by
"set fd [open "|/usr/local/bin/someCprogram" r+]"
The C program is, e.g. :
#include <stdio.h>
main() {
int i;
char buf[10];
while(1) {
bzero(buf, 10);
i=read(STDIN_FILENO, buf, 9);
printf("%s\n", buf);
fflush(stdout);
}
}
I found that after "kill [pid $fd]", the C program does not totally
disappear, but becomes <defunct> zombie, and each "set fd [open|....]"
and "kill [pid $fd]" makes one more zombie, and after the tcltk gui
quit, all these zombies disappear.
Question 1 : Why does this happen?
I don't want these zombies, I want the program to exit immediately after
"kill",
Question 2 : What shall I do to achieve this?
Thank you!!!
X.H.
| |
| Bruce Hartweg 2004-05-18, 11:31 pm |
|
Hao Xu wrote:
> Hello everyone!
>
> In my gui written by tcltk, I open pipelines by
> "set fd [open "|/usr/local/bin/someCprogram" r+]"
>
> The C program is, e.g. :
>
> #include <stdio.h>
>
> main() {
> int i;
> char buf[10];
> while(1) {
> bzero(buf, 10);
> i=read(STDIN_FILENO, buf, 9);
> printf("%s\n", buf);
> fflush(stdout);
> }
> }
>
> I found that after "kill [pid $fd]", the C program does not totally
> disappear, but becomes <defunct> zombie, and each "set fd [open|....]"
> and "kill [pid $fd]" makes one more zombie, and after the tcltk gui
> quit, all these zombies disappear.
>
> Question 1 : Why does this happen?
>
> I don't want these zombies, I want the program to exit immediately after
> "kill",
>
> Question 2 : What shall I do to achieve this?
>
> Thank you!!!
>
The program has exited, it is dead and gone. It is just that the parent
(your script) hasn't reaped it yet. (basically bookeeping in the OS)
if you have expect (and maby tclX - not sure) there are explcit commands
(wait) to call to reap children, but plain tcl doesn't have that directly.
However as part of doing an exec - it will clean up pending children.
so, a) don;t wory a lot about the zombies as they are not eating up resources
(except for a slot in the process table) and b) a simple catch {exec pwd} should
clean them up for you. (or any other simple command that won't waste your time)
bruce
| |
| Iain B. Findleton 2004-05-18, 11:31 pm |
| The problem is that you don't clean up your application when it is
killed. The solution is to trap the signal, close your file handles and
clean up your memory allocation. Have a look at the wait man pages.
Hao Xu wrote:
> Hello everyone!
>
> In my gui written by tcltk, I open pipelines by
> "set fd [open "|/usr/local/bin/someCprogram" r+]"
>
> The C program is, e.g. :
>
> #include <stdio.h>
>
> main() {
> int i;
> char buf[10];
> while(1) {
> bzero(buf, 10);
> i=read(STDIN_FILENO, buf, 9);
> printf("%s\n", buf);
> fflush(stdout);
> }
> }
>
> I found that after "kill [pid $fd]", the C program does not totally
> disappear, but becomes <defunct> zombie, and each "set fd [open|....]"
> and "kill [pid $fd]" makes one more zombie, and after the tcltk gui
> quit, all these zombies disappear.
>
> Question 1 : Why does this happen?
>
> I don't want these zombies, I want the program to exit immediately after
> "kill",
>
> Question 2 : What shall I do to achieve this?
>
> Thank you!!!
>
> X.H.
>
|
|
|
|
|