Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Help with basic bsd unix programming concepts

Author: Robert Hyatt

Date: 10:04:23 05/01/04

Go up one level in this thread


On May 01, 2004 at 11:42:54, William Bryant wrote:

>I could use some basic suggestions or recommendations or resources for two basic
>programming concepts.
>
>1. I want one program (the interface) to open another program (the engine).
>  the engine would use stdin, stdout for communication with the calling program.
>


Simple.  Use the unix pipe() system call to make two pipes.

int pipe1[2], pipe2[2];

pipe(pipe1);
pipe(pipe2);

now create a new process using the fork command:

if (fork() != 0) {
  This is the parent thread;  call your gui code;  if the parent thread
needs to talk to the chess engine, write(pipe1[1], etc) and if it needs to
read from the chess engine read(pipe2[0]);
}
else { child process;
  dup2(pipe1[0],0);  /* makes reads from stdin read from pipe1 */
  dup2(pipe2[1],1);  /* makes writes to stdout go to pipe2 */
  execve("chessprogrampath", etc, etc);
}

Now when the chess program reads from stdin it will block until the parent
writes to pipe 1.  When the chess program writes to stdout, the parent will get
the stuff by reading pipe2...





>2. Once the engine is open, and pondering, how do I _efficiently_ monitor stdin
>during pondering to
>  know when to stop searching?

look at Crafty source.  "select()" lets you poll stdin to see if you have
something to read, without blocking if you do not...





>
>I will be runnin in Mac OSX (built on BSD core) using C not Java.
>
>Thank you in advance.
>
>William



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.