当前位置: 首页 » 产品 » 家居百货 » 正文

linux进程创建

放大字体  缩小字体 发布日期: 2024-09-30 09:30   来源:http://www.baidu.com/  作者:无忧资讯  浏览次数:15
核心提示:  #include#include#includemain(){ pid_t pid;int n=4; pid=fork(); if(pid0) printf(error in fork!/n);else if(pid==0) { n

  #include#include#includemain(){ pid_t pid; int n=4; pid=fork(); if(pid<0) printf("error in fork!/n");else if(pid==0) { n++; printf("I am the child process, my process ID is %d,n=%d/n",getpid(),n); } else { n--; printf("I am the parent process, my process ID is %d,n=%d/n",getpid(),n); }}

  语句“pid=fork()”,产生了两个进程,原来存在的父进程,新出现的子进程。

  父子进程的区别除了PID不同fork函数的返回值也不相同。在父进程中,返回子进程Pid,子进程则返回0;

 
 
[ 产品搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 

 
推荐图文
推荐产品
点击排行
    行业协会  备案信息  可信网站