#include <DML_child.h>
The DML_child uses the DML_process class as a public base class and so therefore has all the convenience funtions of that class immediately available. A DML_child instance can be created as a "blank" child (which will not spawn a new process), or as a child which spawns a process, given by a filename.
The DML_child class is a companion to the DML_master class. With the use of these two classes, the parent and child classes can coordinate set-up and initialization.
pid_t proxy char * name
DML_child() DML_child( const char * ) DML_child( const char *, int ) DML_child( const char *, const char * [ ], int, int ) ~DML_child() setArgs( const char *argv[ ] ) open( const char * ) sendInfoMsg() int beQuiet() int beLoud() attachProxy() int kick() DML_child & print() static printChildren() static killChildren()
#include <DML_child.h> DML_child() DML_child( const char * ) DML_child( const char *, int ) DML_child( const char *, const char * [ ], int waitResponse, int Verbosity )
There are four forms of this constructor: The first creates a blank DML_child object, without spawning off a process. The process can be spawned later using the open() command.
The second creates a DML_child object and spawns off the file named in the argument. If the file doesn't exist, the object is still created, but most of the other functions will subsequently fail when called.
The third is identical to the second, but if the 2nd argument is passed WAIT_RESPONSE it spawns the child then immediately calls the sendInfoMsg() function.
The fourth allows the user to pass command-line arguments to the child process, and in addition specify a default verbosity for the child. The verbosity is used internally to control the display of printf() messages, and is passed to the child to be used at its discretion.
All four forms of this function perform almost the same identical actions. First, the new DML_child object is appended onto the end of the linked list of children. I typically use the same very simple linked-list formulation for many of these classes. Second, the data members are initialized to appropriate "null" values. Third, the arguments to the new child are set and it is actually spawned off. Last, a proxy is attached to the process, if it exists, and it may be sent the infoMsgStruct. The code is self-explanatory.
A child process is spawned off, and a proxy is attached to the child. The child may or may not be passed additional command-line arguments, or sent the sendInfoMsg() message sequence.
~DML_child, DML_child::sendInfoMsg
#include <DML_child.h> ~DML_child()
#include <DML_child.h> setArgs( const char * argv[ ] )
#include <DML_child.h> open( const char *name )
The function uses the "spawnvp" function, which takes a vector of command-line arguments and passes them to the child. It checks to see if custom arguments have been specified for the child: if not, it generates an appropriate list of no arguments: the first argument, however, is always the executable file name. In addition, the function copies the name over into the internal storage, truncating it if necessary.
Note that a more advanced implementation might allow the use of the spawnve function, which passes on environment variables, but that functionality is currently not built into the DML_child class.
DML_child, spawn functions
#include <header> sendInfoMsg()
The Info Message is a tool for synchronizing child and master processes. A master process, which has created a DML_child object and spawned off a child process, can call this function, which effectively waits until the child completes its initialization and responds (manually). Considerable inter-operability is required to use this function, since the programmer must be able to insert function calls into BOTH the parent and child processes. Using this function on a child object which has been previously compiled and doesn't know about the DML_child class will always result in unexpected behaviors (usually the parent who calls this function will hang).
The sendInfoMsg function sends a specific structure to the child object. Information concerning the proxy attached to the child, the child's priority, and the desired child verbosity are transferred. Consequently, this function must be called if the child process needs to know the proxy ID which has been attached to it.
#include <DML_child.h> int DML_child::beQuiet() int DML_child::beLoud()
#include <DML_child.h> DML_child::attachProxy()
#include <DML_child.h> DML_child::kick()
#include <DML_child.h> DML_child & DML_child::print()
#include <DML_child.h> static DML_child::printChildren()
#include <DML_child.h> static DML_child::killChildren()