The process class defines all the methods needed to handle child processes and interprocess communication. A simple way to initiate a child process is to use the command function, which starts a shell and passes it a command line, but this is very crude and does not allow IPC. The process class allows to create a child process and at the same time an object in the calling thread which plays the role of proxy, keeping the local ends of the pipes going to the stdin, stdout and the stderr of the child process. The parent wwlisp can hence write to the stdin and read from the stdout and stderr of its child. It is also possible to redirect from or to a file defined by its path or to redirect from or to an already created stream object, or not to redirect at all and reuse the file-descriptors of the parent. Several processes can be meshed together with several inputs and several outputs being watched, without blocking, by using select . The child process can be either a fork() of the parent, completely initialized like the parent, which starts immediately to evaluate a form given as argument to process-constructor , or a fork()+execv() of the parent, which executes a completely new process of which the path and parameters are given as argument to process-constructor . When the child is a fork() of the parent, only the thread calling process-constructor is replicated in the child, and all the other threads and their belongings become dead memory segments which are cleaned-up and returned to the heap of the child process; the thread running in the child can then itself start new threads for its own sake. Because the process is built by fork(), all the configuration parameters like pointerspace size, etc, are the same as in the parent and cannot be changed; if they must be changed, the programmer should rather start a completely new interpreter by fork()+execv() and provide the parameters on the command string given to process-constructor . When the object in the parent is destroyed, the child process continues its execution but becomes out of reach for the parent. |
Function Type | subr |
Arguments | a form or a string, a series of keywords and values |
Return Value | an object of class process |
Description | creates a child process and an object of class process , which is returned, to play as a proxy to the child; if the first argument is a form (a list which can be evaluated) then the child process is created by fork and it begins immediately to evaluate the form in a completely initialized interpreter; the environment is at the state reached at the moment of the fork, i.e. when process-constructor was executed in the parent; when the evaluation of the form is finished, the child interpreter exits; if the first argument is a string, the string must contain the path to a program followed by parameters for that program; then the child is created by fork+execv, executing the command given in the string; the object receives the following properties:
the keyword 'stdin followed by:
the keywords 'stdout and 'stderr can have the same types of arguments than 'stdin except that when a string is used to specify a filename, this file can be opened in append mode by following it by the keyword 'append the keyword 'maxstring followed by an integer determines the size of the input and output buffers of stdin, stdout and stderr; to avoid to wait undefinitely for a message coming on a pipe, see select |
Example | (setq child(make-instance process '(child-function) 'stdout "childoutput" 'stderr "childlog" 'append)) |
Function Type | subr |
Arguments | an object of class process, an optional keyword, an optional keyword |
Return Value | an unsignedinteger |
Description | destroys the object given as argument; only the proxy is destroyed, not the process itself; as the pipes stdin, stdout and stderr to the child are closed and destroyed, it might well be that this leads the child to stop its activity; after closing the pipes, process-destructor does a waitpid with the parameters passed as second and third arguments; the second and third arguments are one or both keywords: 'WNOHANG, 'WUNTRACED |
Example | (destroy-instance child 'WNOHANG) |
Function Type | subr |
Arguments | an object of class process, an optional integer |
Return Value | an integer |
Description | sends a signal defined by the optional second argument to the process of which the object is a proxy; if the second argument is omitted, the signal is 9 by default, which 'kills' the process but does not destroy the process object in the calling thread; the return value is the same as the kill() system call |
Example | (kill myprocess 2) => sends a ctrl-c signal to the target process |