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应用程序开发标准教程》

最新文章

  1. 没人能阻止你,除了你自己——Keep up the good work!
  2. duapp获取mysql用户名密码等等……
  3. 使用sql对数据库进行简单的增删改查
  4. ABAP DEMO
  5. 编译QT时出现lib/libQtGui.so: undefined reference to `ts_read_raw&#39;的解决办法
  6. java模拟OSUnMapTbl[]
  7. Java小程序---接口中抽象方法的实现(解决了JAVA语言不能多继承的问题)
  8. [置顶]Win2012R2的一个Bug安装群集后可能引发的软件崩溃问题及相应补丁
  9. getline(cin,s) bug workaround
  10. php curl 访问 https站点
  11. Cypher查询语言--Neo4j-MATCH(二)
  12. GP数据库 常用SQL语句
  13. 玩转postman(一)-----基础
  14. 洗礼灵魂,修炼python(72)--爬虫篇—爬虫框架:Scrapy
  15. boost.Asio lib
  16. bzoj3612 平衡 (dp)
  17. java-趣味算法
  18. 将javaweb项目部署到阿里云服务器
  19. 打造 Laravel 优美架构 谈可维护性与弹性设计
  20. random.nextint()

热门文章

  1. Android图片的Base64编码与解码
  2. Testlink1.9.17使用方法(第九章 测试结果分析)
  3. (后端)Sql Server日期查询-SQL查询今天、昨天、7天内、30天(转)
  4. linux卸载openjdk
  5. C#-运算符(四)
  6. 想起以前写的一个爬虫,然后就用C#WinForm写了一个下载小说的软件,比较简单
  7. spreadJs 自动换行功能和自动增高行高
  8. NPOI 笔记
  9. IPerf——网络测试工具介绍与源码解析(4)
  10. June.19 2018, Week 25th Tuesday