歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> return和exit函數的區別

return和exit函數的區別

日期:2017/3/1 9:14:45   编辑:Linux編程

在上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;
}

Copyright © Linux教程網 All Rights Reserved