All Forums |
Register |
Login |
Search |
Subscriptions |
My Profile |
Inbox |
Tool Warehouse |
FAQs |
Resources |
Help |
Member List |
Address Book |
Logout |
|
|
dfunct process on SUA
|
Logged in as: Guest |
Users viewing this topic: none |
|
Login  |
|
|
dfunct process on SUA - May 25, '06, 3:43:06 PM
|
|
|
rfoletta
Posts: 9
Joined: May 17, '06,
Status: offline
|
Hi, I am new to SUA and porting some unix programs to Interix on SUA. My programs create processes with execvp and I have set the SIGCLD signal handler to SIG_IGN so as not to create defunct processes due to not calling wait on the child processes. In other words my programs do not call wait on the child processes and to avoid defunct processes in that situation I am supposed to be able to set the SIGCLD signal to SIG_IGN so that there will be no defunct processes.
Is this a known problem with SUA or is there something else I need to do to avoid creating defunct processes due to not calling wait on the child?
Thanks for any help.
_____________________________
Richard
|
|
|
RE: dfunct process on SUA - May 25, '06, 5:33:45 PM
|
|
|
Rodney
Posts: 3695
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
I haven't noticed a problem, but I haven't gone looking explicitly either.
How have you done the setting of the signal? You need to do it by Posix not SV.
|
|
|
RE: dfunct process on SUA - May 25, '06, 5:39:53 PM
|
|
|
rfoletta
Posts: 9
Joined: May 17, '06,
Status: offline
|
Thanks for your response Rodney.
I call one of my functions with wait_flag set to FALSE because I don't intend on doing a wait on child processes.
So the first time the code below gets called the sigcld_replaced is 0, so it calls setup_signal() which is also shown
below.
Thanks for any help.
if ( wait_flag==FALSE && sigcld_replaced==0 ) {
setup_signal(SIGCLD, SIG_IGN, &old_sigcld);
sigcld_replaced = 1;
}
//----------------------------------------------------------------------------
// static int setup_signal(int sig, void (*func)(int), void **old);
//----------------------------------------------------------------------------
// set the signal handler of signal 'sig' to 'func'. Mask for the signal
// is always set to be empty, e.g: we won't block for signal during signal
// handler execution.
//
// PARAMETERS:
// sig (Unchanged) - signal to handle
// func (Unchanged) - handler for 'sig'
// old (Changed) - old handler before 'func' is installed
//
// RETURN:
// 0 if signal handler is successfully installed
// CCICOM_SYSERR if error
//----------------------------------------------------------------------------
static int setup_signal(int sig, void (*func)(int), void **old)
{
struct sigaction sa, oldsa;
sa.sa_handler = func;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
l_trace_it(TRC_HDR, 7, "Replacing handler for sig %d with handler %ld",
sig, func);
if ( sigaction(sig, &sa, &oldsa) < 0 ) {
error_it(ERR_HDR, "Could not install handler for signal %d", sig);
return CCICOM_SYSERR;
}
l_trace_it(TRC_HDR, 7, "Old handler %ld for sig %d is replaced",
oldsa.sa_handler, sig);
*old = (void *) oldsa.sa_handler;
return 0;
}
_____________________________
Richard
|
|
|
RE: dfunct process on SUA - May 25, '06, 5:48:46 PM
|
|
|
rfoletta
Posts: 9
Joined: May 17, '06,
Status: offline
|
As a side question, should a kill(pid,0) of a processid for a defunct process return 0 or -1 with errno set to ESRCH to show the process is no longer there.
One of my programs called processd is a daemon that is responsible for starting up some of my processes. It keeps track of the processes it started and if it ever detects that one of them has gone away it restarts it. It detects if they have gone away by calling kill(pid,0) on it. The behavior I am seeing is that it is not detecting the process has gone away and I think it may be because there is still a defunct process with the same pid as the process that has gone away.
_____________________________
Richard
|
|
|
RE: dfunct process on SUA - May 25, '06, 9:26:22 PM
|
|
|
Rodney
Posts: 3695
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
> As a side question, should a kill(pid,0) of a processid for...
Paragraph 1, of kill(2) man page:
The kill(2) function sends the signal given by sig to pid, a process or a
group of processes. Sig may be one of the signals specified for
sigaction(2) or it may be 0. If sig is 0, error checking is performed but
no signal is actually sent. (This can be used to check the validity of
pid.)
|
|
|
RE: dfunct process on SUA - May 25, '06, 11:48:31 PM
|
|
|
Rodney
Posts: 3695
Joined: Jul. 9, '02,
From: /Tools lab
Status: offline
|
A SIG_IGN isn't too different from the default action of "discard signal" for SIGCHLD/SIGCLD.
(I'll note that the modern define is SIGCHLD for those wondering).
All it means is that a signal will not be sent to the parent when the child
goes zombie. The child still sits in the zombie state until reaped.
With Interix and many Unix other systems SIGCHLD to SIG_IGN does not predicate that the zombie be reaped.
This is POSIX.1. So you will need to do a wait/waitpid. You can do the wait as replacement
code for the kill code you have; no signals need to be handled. The effect is the same.
Actually, it'll be better because you never have to iterate through a PID list. You just check
and if there's nothing then continue; otherwise you have the PID/PIDs in few loops.
So from (pseudo code):
for i in pidlist
test i
if i dead then restart(i)
end-for
to:
while ((i = waitpid(0, &status, WNOHANG)) > 0)
restart(i)
|
|
|
RE: dfunct process on SUA - May 26, '06, 10:01:26 AM
|
|
|
rfoletta
Posts: 9
Joined: May 17, '06,
Status: offline
|
Thanks for the info Rodney. I'll try your suggestion.
_____________________________
Richard
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
|
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|
|