ipcSkillProcess
ipcSkillProcess(t_command[t_hostName] [tsu_dataHandler] [tsu_errHandler] [tsu_postFunc] [t_logFile] [x_cmdDesc] [x_resDesc] ) =>o_childId
Description
Invokes an operating system process capable of executing SKILL functions in the parent process and opens two additional channels to the child process that let the child send and receive the results of SKILL commands.
fileDescriptor limit is exceeded.Sending Channel
The SKILL command channel is by default bound to file descriptor number 3 in the child process. In addition to whatever input and output the child process may perform, it can write SKILL executable commands on this descriptor that are in turn sent to the parent to be executed. The parent executes these commands during the next cycle of SKILL’s top level without interrupting the current evaluation. The result of this execution is sent back to the child over the SKILL result channel, which is by default bound to file descriptor number 4 in the child process.
The defaults can be over-ridden by supplying the descriptors in the call to ipcSkillProcess. These descriptors must be declared and used by the child process, that is, the parent process cannot force the child process to use a particular pair of channels.
SKILL functions written into the SKILL command channel should have sound syntactic structures. For example,
- Use parentheses when writing function calls, even for infix functions.
-
Ensure that all command expressions are separated by at least a single space character.
Result Channel
The results of executing SKILL functions are sent back on the result channel (descriptor 4 by default). It is up to the child process to read from the result channel.
The buffer for the result channel is separate from all other buffers so the process does not have to empty the buffer if the results are not needed.
Arguments
Examples
Suppose we have a C program, sample.c:
/**********************************************
* Sample process for executing SKILL commands
* in parent process.
**********************************************/
#include "stdio.h"
#define skill_cmd 3
#define skill_result 4
main(int argc, char **argv) { int status;
char s[100];
sprintf(s, "%s", "(let () (println \"Hello world \") (1 + 1))");
printf("Executing %s", s);
fflush(stdout);
status = write(skill_cmd, &s[0], strlen(s));
status = read(skill_result, &s[0], 100);
s[status] = '\0';
printf("Result = %s", s);
fflush(stdout);
exit(0);
}
Compile this into an executable named sample.exe. Then in SKILL:
cid = ipcSkillProcess("sample.exe")
ipc:5
"Hello world"
ipcReadProcess(cid)
"Executing (let () (println \"Hello world\") (1 + 1))"
ipcReadProcess(cid)
"Result = (2)"
cid->exitStatus
0
/**********************************************
* Example of ipcSkillProcess using a Perl script.
**********************************************/
=== Perl script ===
#!/usr/bin/perl
use IO::Handle;
use Fcntl;
# open descriptor 3 and ensure it flushes automatically
open(outPort, ">&3");
outPort->autoflush(1);
print outPort "(myTest)\n";
# open descriptor 4 and ensure it's non-blocking
open(inPort, "<&4");
fcntl(inPort,F_GETFL,$flags);
$flags|=O_NONBLOCK;
fcntl(inPort,F_SETFL,$flags);
# wait a bit and then read
sleep(2);
$inLine=<inPort>;
print "From Perl: $inLine\n";
=== SKILL script ===
procedure( testIpc()
let( (child)
printf("Executing ipc: %s\n" getCurrentTime())
child=ipcSkillProcess("./test.perl")
ipcWaitForProcess(child)
printf("%s\n" ipcReadProcess(child 10))
) ;let
) ;procedure
procedure( myTest()
prog( ()
printf("Executed by Perl\n")
return("123")
) ;prog
) ;procedure
Related Topics
Interprocess Communication Functions
Return to top