linux进程控制开发实例
2024-10-10 18:32:21
fork.c
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> int main(void)
{
pid_t result; result = fork(); if (result == -)
{
printf("Fork Error!\n");
}
else
{
if (result == )
{
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 ;
}
exec.c
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> int main(void)
{
pid_t result; result = fork(); if (result == )
{
if (execlp("ps", "ps", "-ef", NULL) < )
{
printf("Execlp error\n");
}
} return ;
}
waitpid.c
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> int main(void)
{
pid_t pc, pr; pc = fork(); if (pc < )
{
printf("Error fork\n");
}
else if (pc == )
{
sleep();
exit();
}
else
{
do
{
pr = waitpid(pc, NULL, WNOHANG); if(pr == )
{
printf("The child process has not exited!\n");
sleep();
}
}while (pr == ); if (pr == pc)
{
printf("Get child exit code: %d\n", pr);
}
else
{
printf("Some error occured.\n");
}
} return ;
}
参考资料:《嵌入式Linux应用程序开发标准教程》
最新文章
- 没人能阻止你,除了你自己——Keep up the good work!
- duapp获取mysql用户名密码等等……
- 使用sql对数据库进行简单的增删改查
- ABAP DEMO
- 编译QT时出现lib/libQtGui.so: undefined reference to `ts_read_raw&#39;的解决办法
- java模拟OSUnMapTbl[]
- Java小程序---接口中抽象方法的实现(解决了JAVA语言不能多继承的问题)
- [置顶]Win2012R2的一个Bug安装群集后可能引发的软件崩溃问题及相应补丁
- getline(cin,s) bug workaround
- php curl 访问 https站点
- Cypher查询语言--Neo4j-MATCH(二)
- GP数据库 常用SQL语句
- 玩转postman(一)-----基础
- 洗礼灵魂,修炼python(72)--爬虫篇—爬虫框架:Scrapy
- boost.Asio lib
- bzoj3612 平衡 (dp)
- java-趣味算法
- 将javaweb项目部署到阿里云服务器
- 打造 Laravel 优美架构 谈可维护性与弹性设计
- random.nextint()
热门文章
- Android图片的Base64编码与解码
- Testlink1.9.17使用方法(第九章 测试结果分析)
- (后端)Sql Server日期查询-SQL查询今天、昨天、7天内、30天(转)
- linux卸载openjdk
- C#-运算符(四)
- 想起以前写的一个爬虫,然后就用C#WinForm写了一个下载小说的软件,比较简单
- spreadJs 自动换行功能和自动增高行高
- NPOI 笔记
- IPerf——网络测试工具介绍与源码解析(4)
- June.19 2018, Week 25th Tuesday