首页 > 系统服务 > 详细

操作系统学习笔记(三)--进程(下)

时间:2016-03-27 21:01:57      阅读:616      评论:0      收藏:0      [点我收藏+]

上篇随笔不知何故继续编辑发生卡顿,因此重新开一篇随笔继续整理笔记。

 

最近开始学习操作系统原理这门课程,特将学习笔记整理成技术博客的形式发表,希望能给大家的操作系统学习带来帮助。同时盼望大家能对文章评论,大家一起多多交流,共同进步!

本篇文章大致内容为:

  • 进程操作(Operatios on Processes)
  • 进程间协同(Cooperating Processes)
  • 进程间通信(Interprocess Communication)

进程终止(Process Termination)

  1. 正常终止:Process executes last statement and asks the operating system to delete it(exit)  

    - Output data from child to parent(via waiting)

    - Process‘ resources are deallocated by OS

  2. 异常终止:Parent may terminate execution of children processes(abort)

    - Child has exceeded allocated resources 子进程需要的资源高于父进程可提供的资源

    - Task assigned to child is no longer required 子进程的任务不再需要

    - If parent is exiting, in some OSs do not allow child to continue if its parent terminates - cascading termination 若父进程结束,则在某些操作系统中子进程也会终止,层叠终止。

进程间通信(Interprocess Communication)

Independent process 独立进程 不会影响其他进程或被其他进程影响

Cooperating process 协作进程 多个进程一起完成一项任务,其中一个进程的结果可能影响到其他进程或被其他进程所影响

  好处:   1. 信息共享

      2. 提高计算加速比 Conputation speedup

      3. 便于模块化设计 Modularity

      4. 便利:单个用户可以同时完成多项任务 individual user works on many tasks simultaneously

数据交换的机制:IPC - mechanism to exchange data * information

  • 消息传递 Message passing: maximum speed, convenience of communication  使用send和receive两个系统调用
  • 共享储存 Shared memory: easy to implement, smaller amounts of data, slower

下入为消息传递(左图)和共享储存(右图)的结构示意图

技术分享

生产者-消费者问题 Producer-Consumer Problem

操作系统的范例,生产者生产出消息被消费者所消化。

  • A buffer shared by producer & consumer
  • filled by producer & emptued by consumer
  • unbounded-buffer  无界缓冲区
  • bounder-buffer     有界缓冲区

使用*in和*out两个指针,初始时都设置在系统给进程分配的共享内存空间的最低位,若生产者生产出消息,则将消息放在in指针指向的内存空间,in指针+1;若消费者消化消息,则取出out指针指向的内存空间,out+1.

前驱关系:  P --> C : 缓存全空    C-->P : 缓存全满

Insert():  while(((in + 1) % BUFFERSIZE) == out)  ; //do nothing

Remove():  while(in == out)  ;//do nothing

存在两个问题:

  1. 浪费了in指针指向的前一个储存空间(若不浪费则系统无法判断当前存储空间为全满还是全空),可添加计数器解决;
  2. 共享内存在全空或全满时的do nothing,CPU仍在不停判断内存是否为全空或全满,造成忙等(busy waiting),即系统虽然不执行任何执行CPU仍忙。可将此类进程放入阻塞队列,但还存在上下进程同步等问题。

//未完待续

操作系统学习笔记(三)--进程(下)

原文:http://www.cnblogs.com/PaulingZhou/p/5326605.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!