📄 process.c
字号:
/*****************************************Copyright (c)**************************************************** Guangzhou Zhiyuan Electronic Co.,LTD.** graduate school** http://www.zyinside.com****------------------------------------- File Info ------------------------------------------------------** File name: process.c** Last modified Date: 2005-12-30** Last Version: 1.0** Descriptions: Demo multi-process program.**------------------------------------------------------------------------------------------------------** Created by: Chenxibing** Created date: 2005-12-30** Version: 1.0** Descriptions: Preliminary version.****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Descriptions:***********************************************************************************************************/#include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <stdlib.h>#include <sys/types.h>#include <sys/wait.h>/********************************************************************************************************** Function name: mprocess()** Descriptions : Demo for fork usage.** Input : NONE** Output : NONE** Created by : Chenxibing** Created Date : 2005-12-30**-----------------------------------------------------------------------------------------------------** Modified by :** Modified Date: **-----------------------------------------------------------------------------------------------------********************************************************************************************************/int main(int argc, char **argv){ int val, stat; pid_t child; printf("\nTry to create new process.\n"); child = fork(); switch(child) { case -1: // fault perror("fork.\n"); exit(EXIT_FAILURE); case 0: // child process printf("This is child.\n"); printf("\tchild pid is %d\n", getpid()); printf("\tchild ppid is %d\n", getppid()); exit(EXIT_SUCCESS); default: // father process waitpid(child, &stat, 0); printf("This is parent.\n"); printf("\tparent pid is %d\n", getpid()); printf("\tparent ppid is %d\n", getppid()); printf("\tchild exited with %d\n", stat); } exit(EXIT_SUCCESS);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -