📄 test3.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -