fork.c

来自「嵌入式Linux应用程序开发详解源代码,适合开发者」· C语言 代码 · 共 22 行

C
22
字号
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	pid_t result;
	result = fork();
	if(result == -1){
		perror("fork");
		exit;
	}
	else if(result == 0){
		printf("The return value is %d\nIn child process!!\nMy PID is %d\n",result,getpid());
}
	else{
	printf("The return value is %d\nIn father process!!\nMy PID is %d\n",result,getpid());
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?