test3.c
来自「华清远见应用培训班例程源码」· C语言 代码 · 共 51 行
C
51 行
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <string.h>#include <errno.h>int main(int argc, char **argv){ pid_t pid; int retry; //char *p; retry = 5; while ((pid = fork()) < 0) { retry--; if (retry <= 0) { fprintf(stderr, "Fatal error: call fork() faild.\n"); exit(1); } } if (pid == 0) { //char *arg[] = { "env", NULL }; char *arg[] = { "test4", "-afx", NULL }; //char *envp[] = { "PATH=/tmp", "USER=sunq", NULL }; //if (execv("/bin/pwd", arg) < 0) //perror("execve error!"); //if (execlp("ps1", "ps1", "-afx", NULL)<0) //if (execl("/tmp/ps1", "ps1", "-afx", NULL)<0) //if (execl("/tmp/ps1", "/tmp/ps1", "-afx", NULL)<0) //if (execl("./test4", "test4", "-afx", NULL) < 0) if (execv("./test4", arg) < 0) { fprintf(stderr, "ERROR: call execlp() failed: %s\n", strerror(errno)); } exit(0); } return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?