Moderator: Andres Valverde
mridul wrote:Hi all,
I just interfaced my smp engine with winboard and I am facing an unexpected problem.
When I run my engine with two processes , winboard reads only from the first child and not from the second.
A console window opened up and the output from the second child process (of same engine) goes into that window.
Is there some way for a spawned child to inherit the console descriptors of the parent ?
Essentially , I want outputs of both processes to go to winboard.
Thanks,
Mridul
PS : I am not sure if I have made my problem clear above ...
mridul wrote:Hi all,
I just interfaced my smp engine with winboard and I am facing an unexpected problem.
When I run my engine with two processes , winboard reads only from the first child and not from the second.
A console window opened up and the output from the second child process (of same engine) goes into that window.
Is there some way for a spawned child to inherit the console descriptors of the parent ?
Essentially , I want outputs of both processes to go to winboard.
Thanks,
Mridul
PS : I am not sure if I have made my problem clear above ...
mridul wrote:Hi all,
I just interfaced my smp engine with winboard and I am facing an unexpected problem.
When I run my engine with two processes , winboard reads only from the first child and not from the second.
A console window opened up and the output from the second child process (of same engine) goes into that window.
Is there some way for a spawned child to inherit the console descriptors of the parent ?
Essentially , I want outputs of both processes to go to winboard.
Thanks,
Mridul
PS : I am not sure if I have made my problem clear above ...
mridul wrote:Hi all,
I just interfaced my smp engine with winboard and I am facing an unexpected problem.
When I run my engine with two processes , winboard reads only from the first child and not from the second.
A console window opened up and the output from the second child process (of same engine) goes into that window.
Is there some way for a spawned child to inherit the console descriptors of the parent ?
Essentially , I want outputs of both processes to go to winboard.
Thanks,
Mridul
PS : I am not sure if I have made my problem clear above ...
mridul wrote:Hi all,
I just interfaced my smp engine with winboard and I am facing an unexpected problem.
When I run my engine with two processes , winboard reads only from the first child and not from the second.
A console window opened up and the output from the second child process (of same engine) goes into that window.
Is there some way for a spawned child to inherit the console descriptors of the parent ?
Essentially , I want outputs of both processes to go to winboard.
Thanks,
Mridul
PS : I am not sure if I have made my problem clear above ...
mathmoi wrote:mridul wrote:Hi all,
I just interfaced my smp engine with winboard and I am facing an unexpected problem.
When I run my engine with two processes , winboard reads only from the first child and not from the second.
A console window opened up and the output from the second child process (of same engine) goes into that window.
Is there some way for a spawned child to inherit the console descriptors of the parent ?
Essentially , I want outputs of both processes to go to winboard.
Thanks,
Mridul
PS : I am not sure if I have made my problem clear above ...
Hi mridul,
The question is : Why don't you use threads instead of process to create an SMP engine ?
MP
mridul wrote:Would be an overkill to change design to get around a stupid bug
Sven Sch?le wrote:Hi mridul,mridul wrote:Would be an overkill to change design to get around a stupid bug
which bug do you mean here? Some of us have tried to explain that the existing WinBoard architecture does not allow what you intend to do. The engine process being forked by WinBoard has to communicate with the GUI, and the GUI does not allow other partners than those it created itself.
You also can't split a pipe such that either one process or another may write into it. (Neither on Windows nor on UNIX, and this was also never possible in the past.)
If you really need separate processes instead of threads then you might perhaps define the initial engine process as a "master" and maintain a communication protocol to forward messages from a secondary process via the master to the GUI. That's exactly what Tony had already suggested.
Still I think threads would even be the better choice. But you seem to have good reasons against it.
I hope that you will find a good design for your SMP engine, at least I believe it's not an easy task (I never tried it for a chess engine myself).
Sven
Sven Sch?le wrote:You also can't split a pipe such that either one process or another may write into it. (Neither on Windows nor on UNIX, and this was also never possible in the past.)
#include <stdio.h>
main()
{
int i, fd[2];
char buf[100];
pipe(fd);
if(fork())
{
printf("I am the parent\n");
sleep(10); /* wait until offspring is done */
read(fd[0], buf, 31);
buf[31] = 0;
printf("message from my grandchildren:\n%s\n", buf);
} else
{
printf("I am the child\n");
if(fork())
{
printf("I am Alice\n");
write(fd[1],"Alice says Hi!\n", 15);
printf("Alice exits\n");
} else
{
printf("I am Bob\n");
write(fd[1],"Bob says Hello!\n", 16);
printf("Bob exits\n");
}
}
}
H.G.Muller wrote:Sven Sch?le wrote:You also can't split a pipe such that either one process or another may write into it. (Neither on Windows nor on UNIX, and this was also never possible in the past.)
I most emphatically disagree. I have the UNIX programmer's manuals in front of me, (alas, a paper version...) and they clearly state that on a fork() the child inherits all open file descriptors. No exception is made for file descriptors that refer to a pipe.
In the section on pipes says that reading an (empty) pipe produces an error if all write file descriptors on that pipe are closed, a remark that would make no sense if their could be only one process writing the pipe.
And finally, because the proof of the pipe is in the smoking, I can run the following program under Cygwin (the Unix emulator under Windows) compiled with gcc:
- Code: Select all
#include <stdio.h>
main()
{
int i, fd[2];
char buf[100];
pipe(fd);
if(fork())
{
printf("I am the parent\n");
sleep(10); /* wait until offspring is done */
read(fd[0], buf, 31);
buf[31] = 0;
printf("message from my grandchildren:\n%s\n", buf);
} else
{
printf("I am the child\n");
if(fork())
{
printf("I am Alice\n");
write(fd[1],"Alice says Hi!\n", 15);
printf("Alice exits\n");
} else
{
printf("I am Bob\n");
write(fd[1],"Bob says Hello!\n", 16);
printf("Bob exits\n");
}
}
}
Running it shows clearly that two processes (Alice and Bob) can write to the same pipe (fd[1]), and that their messages are then merged and read by the parent (from fd[0]). Despite the fact that the parent is totally unaware that its original child has forked!
Of course this does not proof that under Windows pipes work like this, but when these MicroSoft guys steal an idea the usually steal it entirely...
H.G.Muller wrote:Apparently the Windows CreateProcess call does a lot more than a simple UNIX fork().
So you know how to suppress the console now, but do both engine processes now indeed merge their output into the same pipe, with Winboard listening at the other end?
H.G.Muller wrote:Apparently the Windows CreateProcess call does a lot more than a simple UNIX fork().
So you know how to suppress the console now, but do both engine processes now indeed merge their output into the same pipe, with Winboard listening at the other end?
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 23 guests