⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test3.c

📁 华清远见应用培训班例程源码
💻 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 + -