Spawn a new process
pid_t PtSpawn( const char *cmd, const char * const *argv, const char * const *env, const PtSpawnOptions_t *opt, PtSpawnCbF_t *cb, void *data, PtSpawnCbId_t **csp );
|This control structure exists only until the termination callback is called; don't call PtSpawnSetCallback() or PtSpawnDeleteCallback() after the callback has been called.|
This function spawns a new process and optionally installs a callback that's called when the child process terminates.
Under QNX Neutrino, PtSpawnOptions_t consists of:
If opt is NULL, the function uses the defaults specified in:
extern const PtSpawnOptions_t PtSpawnDefaults;
|By default, the new process inherits all of the parent's valid file descriptors whose values are less than or equal to 9.|
If you want to specify a non-NULL value for opt, it's a good idea to modify a copy of the default structure. For example:
PtSpawnOptions_t my_opts; my_opts = PtSpawnDefaults; my_opts.iov = fd; // Redirect stdout
PtSpawnCbF_t is a function type:
typedef void PtSpawnCbF_t( void *data, int status );
If cb isn't NULL, PtSpawn() attaches a signal handler for SIGCHLD that calls waitpid() to determine whether the child process has terminated. If waitpid() succeeds, the function specified by cb is called, and the signal handler is removed.
If cb is NULL, PtSpawn() doesn't attach any signal handlers or call waitpid().
If you don't need a callback but you also don't want to have to worry about zombie processes, specify cb as PtSpawnNoCb — it's an empty callback function defined in the library.
If cb is NULL but csp isn't, no callback is attached, and *csp is set to NULL.
The process ID of the spawned process, or -1 on error.
See spawn() in the QNX Neutrino Library Reference.
PtSpawnSetCallback(), PtSpawnDeleteCallback(), PtSpawnWait()