cfht_exec(3) manual page
Table of Contents
cfht_exec - launch a new program
#include <cfht/cfht.h>#include <cfht/cfp.h>int cfht_exec(id, string, type, addr)FF_FILE
id;char *string;int type;int *addr;or
PFVexec addr;
extern int cfht_exec_rtprio
libcfht.a
This function
handles the execution of other programs. It is preferred over system(2)
unless the WIF* macros are really needed or the arguments are quoted (see
also cfht_system(3)
). It handles straight replacement, as with exec*(2),
foreground execution with wait, as with system(2)
, background execution
with no further communication, as with fork(2)
exec*(2), background execution
with an exit code updated on completion, or background execution with a
callback on completion.
id is a par file handle for %name substitutions
a la cfp_cursub(3)
. id can be either an open par file (any %variable or
$variable in string will be replaced, before execution, by the appropriate
values based on that par file) or -1 to indicate no substitution is desired.
string is a null terminated invocation string suitable for system(2)
.
type
is one of:
- CFHT_EXEC
- no forking, no return, you’re gone.
- CFHT_EXECFG
- foreground,
waits for child to die and returns exit code a la wait().
- CFHT_EXECBG
- background,
you will never hear from the child process again. Returns pid of child.
- CFHT_EXECBGC
- background with exit code, addr should point to an integer.
The integer will first be set to CFHT_EXEC_NOT_EXITED, cfht_exec will
return the pid of the child, then when the child dies the exit code is
placed into the integer.
- CFHT_EXECBGH
- background with handler, addr should
point to a function. cfht_exec will return the pid of the child. When the
child dies, cfht_exec will call the function with the pid of the child
and the exit code.
cfht_exec_rtprio can be used to set real time priority
after the vfork but before the exec. It defaults to no real time priority,
NOT to whatever the current process happens to be running at.
The
return value can be FAIL for any type, a PID for CFHT_EXECBG, CFHT_EXECBGC,
and CFHT_EXECBGH, and an exit code for CFHT_EXECFG.
The call can fail
(return FAIL) if the command string substitution fails, the fork fails,
or the program requested does not exist. If the program fails, that is
indicated by its return/exit code (0-255 unsigned).
cfht_signal(3)
,
cfht_system(3)
For all calls the routine expects to set up its
own SIGCHLD handler. The caller cannot already have one active.
For the
background cases the caller may block SIGCHLD with cfht_signal_block(3)
around the call, for example to store the returned PID in a table before
the callback happens. This block should be removed as soon as possible.
This depends on the implementation of cfht_signal(3)
. If that implementation
changes, please update this routine.
Table of Contents