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 function spawns a new process and optionally installs a callback that's called when the child process terminates. The arguments are as follows:
Under QNX 4, PtSpawnOptions_t is the same as struct _qnx_spawn_globs (see qnx_spawn_options in the C Library Reference). | |
Under Neutrino, PtSpawnOptions_t consists of:
|
If opt is NULL, the function uses the defaults specified in
extern const PtSpawnOptions_t PtSpawnDefaults;
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[1] = fd; // Redirect stdout
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.
This control structure exists only until the termination callback is called; don't call PtSpawnSetCallback() or PtSpawnDeleteCallback() after the callback has been called. |
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.
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
PtSpawnSetCallback(), PtSpawnDeleteCallback(), PtSpawnWait()