官术网_书友最值得收藏!

exec

At times creating a child process might not be useful, unless it runs a new program altogether: the exec family of calls serves precisely this purpose. exec replaces the existing program in a process with a new executable binary:

#include <unistd.h>
int execve(const char *filename, char *const argv[],
char *const envp[]);

The execve is the system call that executes the program binary file, passed as the first argument to it. The second and third arguments are null-terminated arrays of arguments and environment strings, to be passed to a new program as command-line arguments. This system call can also be invoked through various glibc (library) wrappers, which are found to be more convenient and flexible:

#include <unistd.h>
extern char **environ;
int execl(const char *path, const char *arg, ...);
int execlp(const char *file, const char *arg, ...);
int execle(const char *path, const char *arg,
..., char * const envp[]);
int execv(const char *path, char *constargv[]);
int execvp(const char *file, char *constargv[]);
int execvpe(const char *file, char *const argv[],
char *const envp[]);

Command-line user-interface programs such as shell use the exec interface to launch user-requested program binaries.

主站蜘蛛池模板: 广平县| 通化市| 博罗县| 永善县| 铜梁县| 象州县| 临安市| 兴海县| 温州市| 平潭县| 衡水市| 富民县| 乡宁县| 凌云县| 海晏县| 东辽县| 开化县| 桃江县| 安徽省| 阜阳市| 天镇县| 崇文区| 左权县| 阜南县| 陆河县| 石门县| 明溪县| 满洲里市| 九江县| 靖江市| 临江市| 吉木乃县| 拜城县| 汝阳县| 东丰县| 仁寿县| 灵山县| 海兴县| 德安县| 安仁县| 石河子市|