分类: LINUX
2005-08-19 22:21:13
转载--Linux解释器原理 代码: #include 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 *const argv[]); int execvp(const char *file, char *const argv[]);
代码: /* Program source : showargs.c * * Program name : showargs */ #include
int main(int argc, char *argv[]) { int i; for(i = 0; i < argc; i++) { printf("arg[%d]: %s ", i, argv[i]); } return 0; }
代码: $ pwd /home/kiron $ ./showargs arg1 arg2 arg[0]: ./showargs arg[1]: arg1 arg[2]: arg2
代码: $ ./testexec arg[0]: /home/kiron/showargs arg[1]: addargs arg[2]: ./testexec
代码: /* Program source : mytest.c * * Program name : mytest */ #include int main(void) { execl("/home/kiron/testexec", "testexec", "arg1", "arg2", (char *) 0); return 0; }
代码: $ ./mytest arg[0]: /home/kiron/showargs arg[1]: addargs arg[2]: /home/kiron/testexec arg[3]: arg1 arg[4]: arg2
|