当前位置: 首页 > news >正文

网站建设 模版选择中心邢台网站建设平台

网站建设 模版选择中心,邢台网站建设平台,传奇新开网站,和动物做的网站吗如果代码或文章中#xff0c;有什么错误或疑惑#xff0c;欢迎交流沟通哦~ ## 进程与线程的区别 1. **各自定义**#xff1a; 进程是操作系统进行资源分配和调度的一个独立单位#xff0c;具有一定独立功能的程序关于某个数据集合的依次运行活动。 线程被称为轻量级的进程…如果代码或文章中有什么错误或疑惑欢迎交流沟通哦~ ## 进程与线程的区别 1. **各自定义** 进程是操作系统进行资源分配和调度的一个独立单位具有一定独立功能的程序关于某个数据集合的依次运行活动。 线程被称为轻量级的进程是进程中的实体是被操作系统独立调度和分派的基本单位。 内存 进程每启动一个新的就需要分配独立的内存空间而线程是在同一个进程下共享相同的内存空间因此线程的启动和关闭以及切换的除存需要的系统开销都要比进程小。 通信方式 进程间需要使用进程间通信IPC, Inter-Process Communication的方式来进行通信例如**管道信号消息队列共享内存信号量等。**而同一进程中的线程共享相同的内存空间所以线程之间可以直接访问同一进程内的全局变量静态变量等数据线程间通信比进程间通信要容易得多。 影响范围 由于进程具有独立的内存空间所以一个进程崩溃后在保护模式下不会对其他进程产生影响但是一个线程崩溃后会导致整个进程崩溃。 改变环境 每个独立的进程有一个完全独立的运行环境改变自己的运行环境如改变文件打开方式、改变信号处理方式等不会影响其他进程。而线程则不同一个线程改变其运行环境会影响到同在一个进程中的其它线程。 fork 用fork( )创建进程必须的几个要点 要有一段程序供该进程运行有进程专用的系统堆栈空间有进程控制块PCB在linux中具体实现是task_struct有独立的内存空间 如果没有自己独立的内存空间就称为线程。 线程与进程的区别在于线程没有独立的内存空间。 使用fork来创建进程 //testFork.c #includestdio.h #includeunistd.h int main() { int count1;int child; if(!(childfork())) printf(This is son, his count is: %d. and his pid is: %d\n, count, getpid()); else printf(This is father, his count is: %d, his pid is: %d\n, count, getpid()); }显示结果: This is son, his count is: 2. and his pid is: 302 This is father, his count is: 1, his pid is: 301 fork() 调用会创建一个新的进程这个新的进程是当前进程的复制品被称为子进程。 fork() 函数在父进程中返回新创建的子进程的进程ID而在子进程中返回0。 也就是说如果child fork() 的值为0则说明在子进程中将执行 printf(This is son, his count is: %d. and his pid is: %d\n, count, getpid());语句。 否则说明在父进程中将执行 printf(This is father, his count is: %d, his pid is: %d\n, count, getpid()); }语句。 这两行打印语句的区别在于子进程的count值会加一且父子进程的pid是不同的。 vfork 在Unix和类Unix系统中vfork()是一种特殊的fork()。vfork()创建的子进程可能与父进程共享内存这意味着子进程可以修改父进程的内存空间这与fork()是不同的。执行vfork()函数创建的进程仍然是父进程和子进程的关系有各自独立的进程ID但在一些系统如早期的Unix系统中vfork()创建的子进程和父进程共享同一地址空间父进程在子进程结束执行或者调用exec系列函数之前停止执行。这一点与fork()存在明显的差异。 使用vfork创建子进程 //testVfork.c #includestdlib.h #includestdio.h #includeunistd.h int main( ) { int count1; int child;printf(Before create son, the fathers count is:%d\n, count); if(!(childvfork())){ printf(This is son, his pid is: %d and the count is: %d\n, getpid(), count);exit(0); }else printf(After son, This is father, his pid is: %d and the count is: %d, and the child is: %d\n, getpid(), count, child); }显示结果 Before create son, the fathers count is:1 This is son, his pid is: 4185 and the count is: 2 After son, This is father, his pid is: 4184 and the count is: 2, and the child is: 4185 注意这里有三个打印语句其中两个打印语句是在父进程当中 printf(Before create son, the fathers count is:%d\n, count);和printf(After son, This is father, his pid is: %d and the count is: %d, and the child is: %d\n, getpid(), count, child);这两个语句。 而子进程中的打印语句 printf(This is son, his pid is: %d and the count is: %d\n, getpid(), count);将父子进程共享空间里的count了所以父进程后一条打印语句也会打印得到count2。 用vfork创造线程和父子进程的同步问题 在使用 vfork() 创建子进程后父进程将会被挂起。父进程的执行只会在子进程调用 exit() 或者执行 execve() 开始新程序后才会继续。这是 vfork() 与 fork() 的一个主要区别。 //testVfork.c #includestdlib.h #includestdio.h #includeunistd.h int main() { int count1,i; int child;printf(Before create son,the fathers count is:%d\n,count); if(!(childvfork())){ for(i0;i100;i) { printf(This is son, The i is: %d\n, i);if(i70) break; }printf(This is son, his pid is: %d and the count is: %d\n, getpid(), count);exit(0); } else printf(After son, This is father, his pid is: %d and the count is: %d,and the child is: %d\n,getpid(),count,child); }显示结果 …… …… This is son, The i is: 68 This is son, The i is: 69 This is son, The i is: 70 This is son, his pid is: 4434 and the count is:2 After son, This is father, his pid is: 4433 and the count is: 2, and the child is: 4434
http://www.w-s-a.com/news/994577/

相关文章:

  • 网站拍照的幕布扬中网站建设价位
  • 网站ie兼容性差西安小程序开发的公司
  • 上海网站建设培训app网站开发成本
  • 个人网站icp外贸网站开发 河南
  • 遵义建设网站无锡市规划建设局网站
  • 海外留学网站建设方案门户网站的发布特点
  • 网站建设不赚钱net112企业建站系统
  • 网站建设团队管理模板贵州省住房和城乡建设部网站
  • 曲沃网站建设网上学编程的有哪些比较好的网站
  • 厦门网站建设慕枫学做网站需要多久
  • 爱奇艺做任务领vip网站设计广告图片
  • 中科汇联网站建设手册上海公司名称注册查询网
  • 网站建设电子商务课总结和体会关于做网站书籍
  • 仪征网站建设公司哪家好简单网页制作素材图片
  • 甘肃第九建设集团公司网站潍坊个人做网站
  • 如何做后台网站的教程网站建设 关于我们
  • 极速网站建设哪家好连云港百度推广网站建设
  • 医院网站建设的目标wordpress中英文网站模板
  • 门户型网站开发难度网站导航栏有哪些
  • 推荐做任务网站软件定制开发哪家好
  • 邯郸兄弟建站第三方仓储配送公司
  • 商丘家具网站建设wordpress 添加代码
  • 基础建设的网站有哪些内容成都科技网站建设咨询电话
  • 券多多是谁做的网站招聘网站开发模板
  • 网站主机一般选哪种的企业数字展厅
  • 网站建设该如何学衡水建设局网站首页
  • 高校网站建设工作总结番禺网站开发哪家好
  • 苏州 网站的公司wordpress主页代码
  • 怎么用html做图片展示网站外贸网站建设推广费用
  • 可以做本地生活服务的有哪些网站中油七建公司官网