博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux进程控制开发实例
阅读量:7139 次
发布时间:2019-06-28

本文共 1677 字,大约阅读时间需要 5 分钟。

fork.c

#include 
#include
#include
#include
int main(void){ pid_t result; result = fork(); if (result == -1) { printf("Fork Error!\n"); } else { if (result == 0) { printf("The returned value is %d\nThe child process!!\nMy PID is %d\n", result, getpid()); } else { printf("The returned value is %d\nThe father process!!\nMy PID is %d\n", result, getpid()); } } return 0;}

exec.c

#include 
#include
#include
int main(void){ pid_t result; result = fork(); if (result == 0) { if (execlp("ps", "ps", "-ef", NULL) < 0) { printf("Execlp error\n"); } } return 0;}

waitpid.c

#include 
#include
#include
#include
#include
int main(void){ pid_t pc, pr; pc = fork(); if (pc < 0) { printf("Error fork\n"); } else if (pc == 0) { sleep(5); exit(0); } else { do { pr = waitpid(pc, NULL, WNOHANG); if(pr == 0) { printf("The child process has not exited!\n"); sleep(1); } }while (pr == 0); if (pr == pc) { printf("Get child exit code: %d\n", pr); } else { printf("Some error occured.\n"); } } return 0;}

 

参考资料:《嵌入式Linux应用程序开发标准教程》

转载地址:http://vyvrl.baihongyu.com/

你可能感兴趣的文章
本学期阅读计划
查看>>
Programming Ability Test学习 2-13. 两个有序序列的中位数(25)
查看>>
DOM&&BOM
查看>>
JavaScript严格模式总结
查看>>
07-图
查看>>
20145127《java程序设计》第四周学习总结
查看>>
idea中,使用facets添加完web后,项目已变为web项目,但web.xml中内容经常变为红色,并报错,如何解决?...
查看>>
今晚目标代理模式和迭代器模式
查看>>
http_build_query函数(学习)
查看>>
具有头结点的单链表
查看>>
创建快捷方式
查看>>
选与不选之DFS
查看>>
WinForm 托盘控制应用
查看>>
django自定义模板过滤
查看>>
Questions about UIUC and USC
查看>>
洛谷P1460 健康的荷斯坦奶牛 Healthy Holsteins
查看>>
springboot配置redis+jedis,支持基础redis,并实现jedis GEO地图功能
查看>>
数据流结构
查看>>
python中时间相关问题,仅作为笔记
查看>>
YeoMan 与Angularjs
查看>>