Unix Programming - "[server] <defunct>" processes running

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2005 > "[server] <defunct>" processes running





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 "[server] <defunct>" processes running
Roman Mashak

2005-07-19, 7:49 am

Hello, All!

Why do the following processed appear in 'ps -xwU mrv' output? My test
server application has a skeleton like this:

sockfd=socket(...);
bind(sockfd,...);
listen(sockfd,...);
for (;;) {
newsock=accept(sockfd,...);
if (fork()==0) //new child's born
{
// child process doesn't need it
close(sockfd);
...
close(newsock);
exit(0); //exit status
}
else // here is parent
{
close(newsock);
if ( wait(&status) == -1 ) {
...
}
}
}

So when I test connection by 'telnet localhost port' server succesfully
accepts it, forks child. I terminate connection, but the child is transfered
into zombie-type process. Don't understand why, I closed socket and it
should terminate as well?

How should I deal with this situation?

Thanks!

With best regards, Roman Mashak. E-mail: mrv@tusur.ru


ilko.k.v@gmail.com

2005-07-19, 7:49 am

struct sigaction signal_chld;

//Ignore signal for not zombie process (SIGCHLD)
signal_chld.sa_handler = SIG_IGN ;
signal_chld.sa_flags = SA_RESTART;
sigemptyset(&signal_chld.sa_mask);

ilko.k.v@gmail.com

2005-07-19, 7:49 am

struct sigaction signal_chld;

//Ignore signal for not zombie process (SIGCHLD)
signal_chld.sa_handler = SIG_IGN ;
signal_chld.sa_flags = SA_RESTART;
sigemptyset(&signal_chld.sa_mask);

ilko.k.v@gmail.com

2005-07-19, 7:49 am

I forgot:

//ignore for not "zombie"
if(sigaction(SIGCHLD, &signal_chld, &signal_chld) == -1)
p_error("sigaction signal SIGCHLD",errno,0);

ilko.k.v@gmail.com

2005-07-19, 7:49 am

//ignore for not "zombie"
if(sigaction(SIGCHLD, &signal_chld, &signal_chld) == -1)
p_error("sigaction signal SIGCHLD",errno,0);

Roman Mashak

2005-07-19, 8:48 pm

Hello, ilko.k.v@gmail.com!
You wrote on 19 Jul 2005 02:32:16 -0700:

ik> struct sigaction signal_chld;

ik> //Ignore signal for not zombie process (SIGCHLD)
ik> signal_chld.sa_handler = SIG_IGN ;
ik> signal_chld.sa_flags = SA_RESTART;
ik> sigemptyset(&signal_chld.sa_mask);
According to FAQ SIGCHLD signal is recommended to handle and call 'wait()'
in the signal handle. In your case it's ust ignored, is it right?

With best regards, Roman Mashak. E-mail: mrv@tusur.ru


David Schwartz

2005-07-19, 8:48 pm


"Roman Mashak" <mrv@tusur.ru> wrote in message
news:dbk54f$2mg3$1@relay.tomsk.ru...
> Hello, ilko.k.v@gmail.com!
> You wrote on 19 Jul 2005 02:32:16 -0700:
>
> ik> struct sigaction signal_chld;
>
> ik> //Ignore signal for not zombie process (SIGCHLD)
> ik> signal_chld.sa_handler = SIG_IGN ;
> ik> signal_chld.sa_flags = SA_RESTART;
> ik> sigemptyset(&signal_chld.sa_mask);


> According to FAQ SIGCHLD signal is recommended to handle and call 'wait()'
> in the signal handle. In your case it's ust ignored, is it right?


Yes, ignoring SIGCHLD is a quick and dirty way to solve the problem.
Catching SIGCHLD is superior, though a bit trickier, especially if you have
more than one child running at a time.

DS


Roman Mashak

2005-07-20, 2:49 am

Hello, David!
You wrote on Tue, 19 Jul 2005 18:07:01 -0700:

??>> According to FAQ SIGCHLD signal is recommended to handle and call
??>> 'wait()' in the signal handle. In your case it's ust ignored, is it
??>> right?

DS> Yes, ignoring SIGCHLD is a quick and dirty way to solve the
DS> problem. Catching SIGCHLD is superior, though a bit trickier,
DS> especially if you have more than one child running at a time.
In this case I can easily avoid of using 'wait()' in parent, right?

With best regards, Roman Mashak. E-mail: mrv@tusur.ru


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com