Problem 1 is caused because you are probably overriding the default SIGHUP signal. When a parent process dies, the child process recieves SIGHUP; the default SIGHUP handler calls exit, but if you override it before the fork, then it will stay overridden, and thus you will not die when your parent exits. If you really need SIGHUP to stay overridden in the parent (I can't see why, but you must have a reason), then after the fork you should call "signal(SIGHUP, SIG_DFL)" to return to the standard behavior.
Problem 2 I will leave up to somebody else, since I don't have the gnugo code handy. :-)
PROBLEM 1: It doesn't kill the gnugo process when it exits. (Run it a few times then ask yourself where all your memory went.) What's the right way to do this?
PROBLEM 2: It hangs when called from twogtp. I can't figure out why.
Back to Problem 2 from my previous message.
Here's what is happening. Suppose I run:
perl twogtp-a --black "metamachine" --white "gnugo --mode gtp --quiet"
(There are two versions of twogtp in interface/gtp_examples, and twogtp-a is a little easier for me to parse.)
I can do this from perldb and as soon as pidb is open I can attach gdb to metamachine and/or gnugo. Metamachine stops at line 61:
if (!fgets(client_line, 128, stdin))
waiting for a command in stdin. This it should get when twogtp-a gets up to line 115 and prints "boardsize 19" but at this point deadlock occurs. Note that there is no deadlock if metamachine is run from the shell.
I have an email from David referring to man IPC::Open2 on the dangers of open2. But I can't say I really understand why this deadlock occurs or how it can be avoided.
Potentially cool things could be done using this setup.
Dan
Daniel Bump wrote:
Back to Problem 2 from my previous message.
I have an email from David referring to man IPC::Open2 on the dangers of open2. But I can't say I really understand why this deadlock occurs or how it can be avoided.
Perhaps this has to do with buffering on the file descriptors. setbuf(FILE *f, NULL) switches off buffering for f.
Teun