return和exit函数的区别

在上Linux课的时候,老师提到一句,调用vfork产生的子进程就是为了使用exec族函数来执行其他的代码逻辑。

在子进程退出的时候有两种方式,exit和exec族函数,不能使用return,为什么不能用return呢,为什么只有vfork会不让用return呢?

于是我就写了这样的代码

#include<stdio.h>                                                               
#include<unistd.h>                                                             
#include<stdlib.h>                                                                                                                             
                                                                               
                                                                               
int main()                                                                     
{                                                                               
  pid_t pid;                                                                   
  pid=vfork();                                                                 
  if(pid==0)                                                                   
  {                                                                             
    //child                                                                     
    printf("I am child pid:%d\n",getpid());                                     
····                                                                           
    return 0;16  }                                                                             
  else                                                                         
  {                                                                             
    //father                                                                   
    printf("I am father pid:%d\n",getpid());                                   
  }                                                                             
  return 0;                                                                     
}

猜你喜欢

转载自www.linuxidc.com/Linux/2016-06/132582.htm
今日推荐