Pipe communications, Pipesipc_anon_pipeipc_named_pipe, Pty communications – Crunch CRiSP File Editor 6 User Manual
Page 84: Ptypseudo terminal:ipcipc_pty

Page 84
Pipe Communications
There are two forms of pipes which can be used: anonymous pipes and named pipes. Both types are very
similarly - the difference is in the naming conventions used by the client and server to connect to each other.
Presently, these two forms of communication are only implemented under
Unix.
PipesIPC_ANON_PIPEIPC_NAMED_PIPE
In order to use pipes, you need to execute some other process with its stdin and stdout set to a pair of file
descriptors which are used by CRiSP to communicate with.
The following example shows how to create an anonymous pipe connection to a process:
int
ipc_id = ipc_create(IPC_ANON_PIPE, "date");
The named pipe version of the same thing would be:
int
ipc_id;
mkfifo("/tmp/pipein");
mkfifo("/tmp/pipeout");
ipc_id = ipc_create(IPC_NAMED_PIPE,
"/tmp/pipein",
"/tmp/pipeout",
"date");
If you are using named pipes then you will need to create the named pipe files in the file system. You can do
this with the mkfifo() macro primitive.
Assuming the program to execute starts up correctly, then you can proceed to use the ipc_read() and
ipc_write() functions for communicating with the task, and the ipc_register() function for handling callbacks.
You can detect the death of the child process by attempting to read from the IPC channel. If you read back
zero bytes, then the other end of the pipe has most likely terminated. Alternatively you may use the
ipc_register() callback to register notification on the death of a process.
{button See Also, ALink(ipc,,,)}
PTY Communications
PTY communication is similar to using pipes for IPC communication. PTYs are only implemented under
Unix, and it is this mechanism which allows Unix to support remote logins and multiple command terminal
windows under X-Windows. (By contrast, Microsoft Windows does not support the PTY concept which is
why you cannot telnet or rlogin into a Windows based machine).
PTYPseudo
terminal:IPCIPC_PTY
Using a pty for communication is best suited to very specific types of applications - applications which use
stdin and stdout for user interaction, but for which using a pipe may cause a problem.
One area where a PTY may be more useful than a pipe is for a program which does buffered output. Most
programs use the printf() function to display messages to the user. The default ANSI C library sets all output
from a program to the terminal to be line buffered, whereas output to a disk file or pipe is block buffered.
This can cause problems when using some programs with a pipe as you may not see any output from the
program until sometime after you have typed something in to them.
You can get around this problem by using a PTY which fools the program to believe that it is directly
connected to a terminal and thus behave correctly.
The way to create a PTY connection is as follows:
int
ipc_id = ipc_create(IPC_PTY, "date");
Assuming the program to execute starts up correctly, then you can proceed to use the ipc_read() and
ipc_write() functions for communicating with the task, and the ipc_register() function for handling callbacks.
You can detect the death of the child process by attempting to read from the IPC channel. If you read back