wait()系统调用分别演示在父子进程
2024-09-08 01:00:08
废话不多说开代码
在父进程调用wait()
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
int main(int argc,char *argv[]){
int rc=fork();
if(rc==0){
printf("i am child pid=%d\n",(int)getpid());
}else{ int wc=wait(NULL);
printf("i am father wc=%d",wc); } return 0;
} [root@localhost codec5]# ./t5
i am child pid=3243
i am father wc=3243[root@localhost codec5]# cat t5.c
在父进程调用 成功返回子进程的id号
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
int main(int argc,char *argv[]){
/*int rc=fork();
if(rc==0){
printf("i am child pid=%d\n",(int)getpid());
}else{
*/
int wc=wait(NULL);
printf("i am father wc=%d",wc); return 0;
} [root@localhost codec5]# ./t5
i am father wc=-1
在父进程调用 wait 失败返回 -1
在子进程里调用wait()
由于子进程并没有创建再创建子进程所以返回值是-1
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
int main(int argc,char *argv[]){
int rc=fork();
if(rc==0){
int wc=wait(NULL);
printf("i am child pid=%d,wc=%d\n",(int)getpid(),wc);
}else{ printf("i am father ");
} return 0;
} [root@localhost codec5]# ./t5 i am father [root@localhost codec5]# i am child pid=3337,wc=-1
最新文章
- 江太公:javascript count(a)(b)(c)(d)运行过程思考
- PHP与Javascript的混合测试
- Unity Shaders Vertex &; Fragment Shader入门
- 配置yii访问远程数据库
- (转)使用pth文件,让python方便的import自己写的模块
- Sockets
- iOS wkwebview懒加载中遇到的问题
- 定时任务调度工作(学习记录 二)timer定时函数的用法
- 一道dfs和dp结合的好题 --- Longest Run on a SnowboardUVA-10285
- 多线程之Executors基本使用
- Python3+Scapy安装使用教程
- sys os
- C#编写CLR函数
- linux /mac 下 go环境变量配置
- jquery弹窗时禁止body滚动条滚动
- hive sequencefile导入文件遇到FAILED: SemanticException Unable to load data to destination table. Error: The file that you are trying to load does not match the file format of the destination table.错误
- 进程间通信--POSIX信号量
- jQuery的$ .ajax防止重复提交的方法
- bzoj 4551
- 使用js/jquery查找iframe中的
热门文章
- 玩转控件:GDI+动态绘制流程图
- 多测师浅谈 学员实现价值就是我们的幸福_高级讲师肖sir
- 多测师_肖sir_性能测试之性能测试了解001(jmeter)
- 【转】了解nodejs、javascript间的关系!bom&;dom&;ecmascript
- 苏州6617.9373(薇)xiaojie:苏州哪里有xiaomei
- jenkins 构建 job 并获取其状态的实现
- c语言版去除源代码注释
- centos8上redis5在生产环境的配置
- Curl可以模拟浏览器
- CTCall简介(后续会继续补充)