2.1 Child Processes

The fragment processmanager is concerned with child processes. An instance of the process pattern in this fragment is attached to a binary file by initializing it with a file specification, like

'/bin/someApplication' -> aProcess.init;
In the following, aProcess denotes an instance of the pattern process, which has been attached to a binary file.

One has the option to set up arguments for an instantiation of the binary, using aProcess.argument.append, once for each argument. Afterwards, the process can be instantiated with aProcess.start. In the following, this instantiation is referred to as the child process. When it has been started, it is possible to change its life cycle and to adjust to it: aProcess.stop causes the child process to be killed, aProcess.awaitStopped causes this process to sleep until the child process terminates, and aProcess.stillRunning is a predicate which returns true if the child process has not yet terminated.

The onStart virtual is a hook, into which one can put code to be executed immediately after the child process has been started, and the onStop virtual is a hook which is executed when stop has stopped the process. Please notice that onStop will NOT be executed in the (typical) case when the child process terminates for any other reason, e.g. when it terminates normally.

The remaining pattern attributes of process are concerned with inter-process communication. The network of inter-process communication must be defined before the child processes are started. ConnectToProcess and connectInPipe enter a reference to another process object and connect the referred child processes in a pipeline. redirectFromFile arranges for the child process to take standard input from the specified file, and redirectToFile makes it redirect standard output to the given file.

RedirectFromChannel enters the writeEnd of a pipe and makes the child process accept standard input from that pipe, and redirectToChannel enters the readEnd of a pipe and makes the child process send standard output to it. The entered parameter is declared to be a (specialization of a) stream. The reason for this is that a future release may accept a broader range of types of objects entered; it should, for instance, be possible to use sockets.

ConnectErrToProcess, redirectErrToFile and redirectErrToChannel work like connectToProcess, redirectToFile and redirectToChannel with the exception that they use the standard error from the process, rather than the standard output. It is possible to connect both the standard output and the standard error to the same stream.


Process Libraries - Reference Manual
© 1994-2002 Mjølner Informatics
[Modified: Friday October 20th 2000 at 14:22]