fork执行一个进程

https://coolr321.github.io/2018/10/30/%E4%B8%80%E4%B8%AAfork-%E8%B0%83%E7%94%A8%E7%9A%84%E4%BE%8B%E5%AD%90/

// Linux 程序b
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[], char **environ) {
    int pid;
    pid = fork();
    if(pid < 0) {
        printf("Fork failed.\n");
        exit(1);
    } else if(pid == 0) {
        printf("Call another program a.out.\n");
        execve("a.out", argv, environ);
    }
    exit(0);
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/hshy/p/11363927.html
0条评论
添加一条新回复
  
今日推荐