- Subject: Re: Annoying problem with subprocesses
- From: sdupont@xxxxxxx
- Date: Tue, 28 Jan 2003 11:48:49 +0000
On Mon, 27 Jan 2003 11:04:21 -0500
"John E. Davis" <davis@xxxxxxxxxxxxx> wrote:
> sdupont@xxxxxxx <sdupont@xxxxxxx> wrote:
> >1. the process (0) gets killed in jed_close_process(),
> > signal_handler will do cleanup (but not yet)
> >2. new process (1) is created with open_process(),
> > no cleanup done so far
> >3. sys_input_pending() is trying to read_process_input()
> > and than it happens "what never should happen":
> > Since cleanup wasn't done or wasn't ready, Num_Subprocesses
> > is 2 (0 and 1) though in fact there is only one (1).
>
> "what should never happen" happens in the get_process function. And
> that only happens if p->flags is 0. It is not clear to me how
> p->flags is getting set to 0. The only place I can see this happening
> is in the child_signal_handler after the call to waitpid. Does adding
> a check for status==0 after waitpid help? That is, use:
>
> pid = (int) waitpid (-1, &status, WNOHANG | WUNTRACED);
> if (pid == -1)
> {
> if (errno == ECHILD) break;
> continue;
> }
> .
> .
> /* What else?? */
>
> /* ADD CHECK HERE */
> if (status == 0)
> continue;
>
> p = Processes;
> pmax = p + MAX_PROCESSES;
>
> If that solves the problem, my next question is what does status==0
> mean?
> [...]
I tried the above but it doesn't help. In fact, in all the tests
I did, status is != 0.
So I spent another couple of hours trying to track this error down.
After a lot more printfs I found that it isn't necessary to force
the call to get_process_status(), since the problem appears *after*
the cleanup is done. The problem is that sys_input_pending() is trying
to read from the wrong fd (read descriptor), though get_process_status()
*has* done the cleanup (adjustment of Subprocess_Read_fds array).
So I checked get_process_status() again and there seems to be a bug
in the adjustment since Subprocess_Read_fds[i][0] (the actual fd)
is checked and not Subprocess_Read_fds[i][1] (the jed rep.) as it should(?):
static void get_process_status (Process_Type *p) /*{{{*/
{
[...]
/* Adjust the array of read descriptors */
i = 0;
while (i < Num_Subprocesses)
{
/* if (Subprocess_Read_fds[i][0] == slfd) WRONG? */
if (Subprocess_Read_fds[i][1] == slfd)
break;
i++;
}
/*fd = Subprocess_Read_fds [i][0]; WRONG? */
fd = Subprocess_Read_fds [i][1];
[...]
if (Max_Subprocess_FD == fd)
{
i = 0;
fd = -1;
while (i < Num_Subprocesses)
{
/*if (Subprocess_Read_fds[i][0] > fd)
fd = Subprocess_Read_fds[i][0]; WRONG? */
if (Subprocess_Read_fds[i][1] > fd)
fd = Subprocess_Read_fds[i][1];
i++;
}
Max_Subprocess_FD = fd;
}
Doing this little change, subprocesses work as expected (=GREAT!)
Greetings
Stefan
[2003 date index]
[2003 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]