fork 和 execve

2020-07-17  本文已影响0人  苍老师的眼泪
#include <stdio.h>
#include <sys/types.h> 
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>

int main() {

    int child_pid = fork();

    if (child_pid != 0) {
        printf("parent process\n");
        waitpid(child_pid, NULL, 0);
        printf("parent process continue\n");
    } else {
        printf("child begin to execute\n");
        
        char *argv[]={"cp","a","b", NULL};

        char *envp[]={0,NULL}; 

        execve("/usr/bin/cp",argv,envp);

    }

    return 0;
    
}

上一篇 下一篇

猜你喜欢

热点阅读