Execute a program in a child process
Overview
Routines to execute a program in a child process More…
// typedefs typedef enum te_exec_param_type te_exec_param_type; typedef enum te_sched_param_type te_sched_param_type; typedef struct te_exec_param te_exec_param; typedef te_exec_param te_sched_param; typedef struct te_exec_affinity_param te_exec_affinity_param; typedef te_exec_affinity_param te_sched_affinity_param; typedef struct te_exec_priority_param te_exec_priority_param; typedef te_exec_priority_param te_sched_priority_param; typedef struct te_exec_workdir_param te_exec_workdir_param; // enums enum te_exec_param_type; enum te_sched_param_type; // structs struct te_exec_affinity_param; struct te_exec_param; struct te_exec_priority_param; struct te_exec_workdir_param; // global functions pid_t te_exec_child(const char* file, char*const argv[], char*const envp[], uid_t uid, int* in_fd, int* out_fd, int* err_fd, const te_exec_param* exec_param); // macros #define TE_EXEC_CHILD_DEV_NULL_FD
Detailed Documentation
Routines to execute a program in a child process
Typedefs
typedef enum te_exec_param_type te_exec_param_type
Kinds of process parameters.
typedef enum te_sched_param_type te_sched_param_type
Use te_exec_param_type
in the new code.
Deprecated
typedef struct te_exec_param te_exec_param
Process parameter.
typedef te_exec_param te_sched_param
Use te_exec_param
in the new code.
Deprecated
typedef struct te_exec_affinity_param te_exec_affinity_param
Data specific for CPU affinity type (TE_EXEC_AFFINITY
).
typedef te_exec_affinity_param te_sched_affinity_param
Use te_exec_affinity_param
in the new code.
Deprecated
typedef struct te_exec_priority_param te_exec_priority_param
Data specific for priority type (TE_EXEC_PRIORITY
).
typedef te_exec_priority_param te_sched_priority_param
Use te_exec_priority_param
in the new code.
Deprecated
typedef struct te_exec_workdir_param te_exec_workdir_param
Data specific for working directory type (TE_EXEC_WORKDIR
).
Global Functions
pid_t te_exec_child(const char* file, char*const argv[], char*const envp[], uid_t uid, int* in_fd, int* out_fd, int* err_fd, const te_exec_param* exec_param)
Function to base system()-like and popen()-like functions on it. You MUST use uid parameter instead of “su - user -c”, because su makes one more fork, and you do not know how to kill this grandchild process.
The function: 1) creates pipes (if necessary) to communicate with a child process; 2) fork()’s the child process; 3) modifies standard file descriptors of the child process according to in_fd
out_fd
err_fd
; 4) executes specified program in the child process;
if a file descriptor location is NULL
, copy of the respective standard file descriptor will be inherited by the child; if a file descriptor location is TE_EXEC_CHILD_DEV_NULL_FD
, the respective standard file descriptor of the child will be redirected to /dev/null
If you use this fuction from agent, this process SHOULD be catched by ta_waitpid() or killed by ta_kill_death().
Parameters:
file |
file to execute |
argv |
command line arguments terminated by |
envp |
environment variables terminated by |
uid |
user id to execute the file; use -1 for default |
in_fd |
location to store file descriptor of pipe to stdin of the process; see note |
out_fd |
location to store file descriptor of pipe to stdout of the process; see note |
out_fd |
location to store file descriptor of pipe to stderr of the process; see note |
exec_param |
Array of process parameters. The last element must have the type TE_EXEC_END and data pointer to |
Returns:
pid value, positive on success, negative on failure