Re: Still more pty problems
Re: Still more pty problems
- Subject: Re: Still more pty problems
- From: Ingemar Ragnemalm <email@hidden>
- Date: Sat, 17 Sep 2011 21:17:07 +0200
Jonas Maebe wrote:
On 16 Sep 2011, at 22:12, Ingemar Ragnemalm wrote:
Thanks, but it doesn't explain why it would fail after a pretty exact number of runs. And it still does, with the correction.
You also have to reap the child processes. So something like this:
void RunTest(int i)
{
int pty, childpid, res;
switch((childpid=forkpty(&pty, NULL, NULL, NULL)))
{
case -1: // Error
printf("pty error after %d\n", i); exit(1);
case 0: // Child
_exit(0);
default: // Parent
do
{
res = close(pty);
} while ((res == -1) && (errno == EINTR));
do {
res = waitpid(childpid,NULL,0);
} while ((res == -1) && (errno == EINTR));
}
}
You are right, that did it for this example! Only one detail: AFAIK the
EINTR checks are superfluous in the default setting, since the default
behavior is to restart the interrupted call. That will save some lines
of code. That is, granted that this is default on OSX and not only on
some other Unix.
So if I miss a close, it locks up after about 30 runs since I run out of
ptys, and if I miss a waitpid I will run out of child processes since I
get too many zombies. I suppose that the limit is 256.
/Ingemar
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden