文件名称:File-Operations
-
所属分类:
- 标签属性:
- 上传时间:2015-10-29
-
文件大小:3.69kb
-
已下载:0次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
在 Linux 中 FIFO 是一种进程之间的管道通信机制。Linux 支持完整的 FIFO通信 机制。 本实验内容,通过使用文件操作,仿真 FIFO(先进先出)结构以及生产者-消费者运行模型。
本实验中需要打开两个虚拟终端,分别运行生产者程序(producer)和消费者程序(customer)。此时两个进程同时对同一个文件进行读写操作。因为这个文件是临界资源,所以可以使用文件锁机制来保证两个进程对文件的访问都是原子操作。
先启动生产者进程,它负责创建仿真 FIFO 结构的文件(其实是一个普通文件)并投入生产,就是按照给定的时间间隔,向 FIFO 文件写入自动生成的字符(在程序中用宏定义选择使用数字还是使用英文字符),生产周期以及要生产的资源数通过参数传递给进程(默认生产周期为 1s,要生产的资源数为 10 个字符)。
后启动的消费者进程按照给定的数目进行消费,首先从文件中读取相应数目的字符并在屏幕上显示,然后从文件中删除刚才消费过的数据。为了仿真 FIFO 结构,此时需要使用两次复制来实现文件内容的偏移。每次消费的资源数通过参数传递给进程,默认值为10 个字符。 -Linux is in FIFO pipe communication mechanism between processes. Linux supports a full FIFO communication mechanism. The experiment content, through the use of file operations, simulation FIFO (First In First Out) structure as well as producer- consumer model is run.
In this study we need to open two virtual terminals, each running program producers (producer) and consumer programs (customer). At this point two processes simultaneously on the same file for read and write operations. Because this document is the critical resource, so you can use the file locking mechanism to ensure access to the file two processes are atomic.
Producers first start process, it is responsible for creating the simulation FIFO file structure (actually a common file) and put into production, is in accordance with a given time interval, automatically generated characters written into the FIFO file (using macros define the selection the use of digital still use English characters), the production cycle and t
本实验中需要打开两个虚拟终端,分别运行生产者程序(producer)和消费者程序(customer)。此时两个进程同时对同一个文件进行读写操作。因为这个文件是临界资源,所以可以使用文件锁机制来保证两个进程对文件的访问都是原子操作。
先启动生产者进程,它负责创建仿真 FIFO 结构的文件(其实是一个普通文件)并投入生产,就是按照给定的时间间隔,向 FIFO 文件写入自动生成的字符(在程序中用宏定义选择使用数字还是使用英文字符),生产周期以及要生产的资源数通过参数传递给进程(默认生产周期为 1s,要生产的资源数为 10 个字符)。
后启动的消费者进程按照给定的数目进行消费,首先从文件中读取相应数目的字符并在屏幕上显示,然后从文件中删除刚才消费过的数据。为了仿真 FIFO 结构,此时需要使用两次复制来实现文件内容的偏移。每次消费的资源数通过参数传递给进程,默认值为10 个字符。 -Linux is in FIFO pipe communication mechanism between processes. Linux supports a full FIFO communication mechanism. The experiment content, through the use of file operations, simulation FIFO (First In First Out) structure as well as producer- consumer model is run.
In this study we need to open two virtual terminals, each running program producers (producer) and consumer programs (customer). At this point two processes simultaneously on the same file for read and write operations. Because this document is the critical resource, so you can use the file locking mechanism to ensure access to the file two processes are atomic.
Producers first start process, it is responsible for creating the simulation FIFO file structure (actually a common file) and put into production, is in accordance with a given time interval, automatically generated characters written into the FIFO file (using macros define the selection the use of digital still use English characters), the production cycle and t
(系统自动生成,下载前可以参看下载内容)
下载文件列表
sy4/customer.c
sy4/mylock.h
sy4/producer.c
sy4/sy4.c
sy4/
sy4/mylock.h
sy4/producer.c
sy4/sy4.c
sy4/
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.