Defunct Processes
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Defunct Processes




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Defunct Processes  
Rookie


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 01:48 AM

Hi,

I am trying to pass a kill(childpid,signal) from a parent process to a child
process when the parent receives a SIGINT signal. I am able to catch the
signal properly at the parent.

But unfortunately when I press ctrl-C only the parent's signal handler is
executing (which is printing a line and sending kill's to the children).I
also put a sleep in the parent's signal handler to see what was happening. I
then did a ps and saw that all the children had been labeled as <defunct>
even before the parent's exit() was called in its signal handler, then when
the parent exited all the children were automatically killed without any
signal handler being called.

Firstly I would appreciate it if someone could tell me what I am doing
wrong. And also whats this <defunct> process thing?








[ Post a follow-up to this message ]



    Re: Defunct Processes  
Walter Roberson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 07:48 AM

In article <cl1q3f$dc6$1@gist.usc.edu>,
Rookie <dominicjoseph@rediffmail.com> wrote:
:I am trying to pass a kill(childpid,signal) from a parent process to a chil
d
:process when the parent receives a SIGINT signal. I am able to catch the
:signal properly at the parent.

:But unfortunately when I press ctrl-C only the parent's signal handler is
:executing (which is printing a line and sending kill's to the children).

None of the output routines are marked as safe to use within a signal
handler in POSIX, so you should instead be setting a volatile variable
and returning.

[url]http://docsun.cites.uiuc.edu/sun_docs/C/solaris_9/SUNWdev/MTP/p40.html#GEN-95948[/
url]

:I
:also put a sleep in the parent's signal handler to see what was happening. 
I
:then did a ps and saw that all the children had been labeled as <defunct>
:even before the parent's exit() was called in its signal handler, then when
:the parent exited all the children were automatically killed without any
:signal handler being called.

:Firstly I would appreciate it if someone could tell me what I am doing
:wrong. And also whats this <defunct> process thing?

That means that the child process has exitted but the parent has
no issued a wait() or wait3() to collect the status of the child.
Some state for the child process must be maintained because the parent
might ask for the state information later. Unix deals with that
by marking the process as dead and then releasing the process resources
except for the process control block.
--
Whose posting was this .signature Google'd from?





[ Post a follow-up to this message ]



    Re: Defunct Processes  
Rich Teer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 07:48 AM

On Mon, 18 Oct 2004, Rookie wrote:

> I am trying to pass a kill(childpid,signal) from a parent process to a chi
ld
> process when the parent receives a SIGINT signal. I am able to catch the
> signal properly at the parent.
>
> But unfortunately when I press ctrl-C only the parent's signal handler is
> executing (which is printing a line and sending kill's to the children).I

Source code, please.  Also, printing a line (in fact, calling any of the
standard IO library functions) is not a good idea from a signal handler
(although in a small program you might get away with it).

> Firstly I would appreciate it if someone could tell me what I am doing

Hard to see without seeing your code.

> wrong. And also whats this <defunct> process thing?

A defunct process is a zombie--and a zombie is a process that
has died and whose status hasn't been reaped by its parent.

If the zombie's parent terminates before reaping the child's
status, the child is inherited by init, and IT reaps the
child's status.

I explain all this in greater detail in my book, Solaris
Systems Programming.  Have a look around the book's web site
(www.rite-group.com/rich/ssp), and perhaps order a copy from
Amazon.com using the link supplied.

HTH,

--
Rich Teer, SCNA, SCSA, author of "Solaris Systems Programming",
published in August 2004.

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich





[ Post a follow-up to this message ]



    Re: Defunct Processes  
Rookie


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 07:48 AM

> Hard to see without seeing your code.

Here is the code

Parent:



void signalHandler(int n)
{
int i;
for(i=0;i<noOfChildren;i++)
kill(childpids[i],SIGINT);
}

void main()
{
(void) signal(SIGINT,signalHandler);
.
.
.
.
}


Child:

void childSignalHandler(int n)
{
flag=1;
}

void main()
{
(void) signal(SIGINT,childSignalHandler);
.
.
.
.
}







[ Post a follow-up to this message ]



    Re: Defunct Processes  
Rich Teer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 07:48 AM

On Mon, 18 Oct 2004, Rookie wrote:
 
>
> Here is the code
>
> Parent:
>
>
>
> void signalHandler(int n)
> {
>     int i;
>     for(i=0;i<noOfChildren;i++)
>         kill(childpids[i],SIGINT);
> }
>
> void main()

main() is NOT void!

> {
>     (void) signal(SIGINT,signalHandler);

You're not checking for errors, either.

Also, you need to show ALL of your code.  A few isolated lines
out of context doesn't show much...

(And on a stylistic note, some white space and not using
MiXeD case identifiers would make your code more readable.)

--
Rich Teer, SCNA, SCSA, author of "Solaris Systems Programming",
published in August 2004.

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich





[ Post a follow-up to this message ]



    Re: Defunct Processes  
seemanta dutta


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 07:48 AM

<snip>


>
> :Firstly I would appreciate it if someone could tell me what I am doing
> :wrong. And also whats this <defunct> process thing?


You are not doing anything illegal here. You just forgot to call
wait().
Defunct processes are called zombie processes and get created when the
parent does not call wait(). After a call to wait the parent can
collect the return status of the child along with a lot of other
details which are packed in an integer value.

In case you don't want your children to become zombies and yet also
don't want to wait for them to die, you can use the signal call to
ignore SIGCHLD signal which is emitted when the child exits.

#include<signal.h>

signal(SIGCHLD,SIG_IGN);

That should do the trick.
For more on these things you may want to refer to the unix programming
book by Stevens ( Advanced Unix programming).

regards,
Seemanta





[ Post a follow-up to this message ]



    Re: Defunct Processes  
Jim Cochrane


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-19-04 10:51 PM

In article <Pine.SOL.4.58.0410182117550.17681@zaphod.rite-group.com>, Rich Teer wrote:[vbcol
=seagreen]
> On Mon, 18 Oct 2004, Rookie wrote:
> 
>
> ...
>
> (And on a stylistic note, some white space and not using
> MiXeD case identifiers would make your code more readable.)[/vbcol]

He's probably been writing Java for too long and forgot where the
underscore character is on his keyboard.

--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line
 to
get through my spam filter.]





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:48 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register