-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfork.c
More file actions
42 lines (36 loc) · 973 Bytes
/
fork.c
File metadata and controls
42 lines (36 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*************************************************************************
>文件名称: fork.c
>程序功能:检验fork函数返回值
>注意事项:
>创建时间: 2014年12月10日 星期三 19时50分30秒
>保持好奇,虚心接受
************************************************************************/
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<errno.h>
#include<stdlib.h>
#define FALSE 0
#define TRUE 1
#define OK 1
#define ERROR 0
#define MAXSIZE 100
int main(int argc, char *argv[])
{
pid_t pid; //pid_t为头文件<sys.types.h>中int的宏定义
printf("Process Creation Study\n");
pid = fork();
switch(pid)
{
case 0:
printf("Child process is running,CurPid is %d, ParentPid is %d\n",pid, getppid());
break;
case -1:
printf("Process creation faild\n");
break;
default:
printf("Parent process is running, ChildPid is %d, MyPid is %d\n", pid, getpid());
break;
}
exit(0);
}