linux C进程的执行函数exec系列

  • exec系列
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
    pid_t pid;
    pid_t pid2;
    pid=fork();
    char buf[1024];
    if(pid==0)
    {
        pid2=getpid();
        printf("this is a child process %d\n",pid2);
        sprintf(buf,"/proc/%d/maps",pid2);//显示进程映射了的内存区域和访问权限
        execlp("/bin/cat","cat",buf,NULL);
    }
    else
    {
        printf("I am the parent %d and create the child %d\n",getpid(),pid);
        sleep(40);
        wait(NULL);
        printf("child complete!");
    }
    return 0;
}

输出结果:

猜你喜欢

转载自www.cnblogs.com/saintdingspage/p/12180043.html