C代写:CS312FileCopywithSemaphoresandSharedMemory


代写一个操作系统作业,实现支持并发读写的文件拷贝,需要使用Semaphores和Shared Memory.

Assignment Information

This program shall be written in C, compiled with the following options: -Wall
-Wextra-std=c99, and display no errors and no warnings. Do not submit
executable files (only C source files).
In this assignment, you are to implement a program that copies a large file
from its standard input (stdin) to the standard output (stdout) using
semaphores and shared memory.
The program shall create an array of M shared memory segments of size N each,
where M and N are positive integer numbers and the only command line
parameters. If there are fewer or more command line parameters, the program
shall report an error message and terminate. Use functions shmget, shmat,
shmdet, and shmctl to operate the shared memory.
The program shall then create three semaphores (use functions semget, semop,
and semctl) and fork a child process. The shared memory segments and the
semaphores will be inherited by the child.
The program shall execute an M-buffer producer-consumer algorithm, as
explained in class. The producer process shall read up to N bytes from stdin
into the first available shared memory segment, while the consumer process
shall write up to N bytes from the first available shared memory segment
tostdout. Since the last read operation is likely to result in fewer than N
bytes, there must be a way for the producer to provide the length of the used
part of each buffer to the consumer (hint: allocate N+sizeof(int) bytes for
each buffer).
The child process shall terminate upon writing the buffer that has fewer than
N bytes. The parent process shall wait4 for the child, then destroy all
semaphores and shared memory segments, print the total elapsed time to stderr
and terminate itself.
Test your program by copying the large file from the “Explore a Big File”
project. The source and the target files must be identical (command diff
source.file target.file must not display anything).
Once you know the program is correct, run it each value of M on the list
1,2,4,8, and 16, and each value of N on the list 100, 1kB, 10kB, 100kB, and
1MB (the total of 25 runs; you may want to automate the process by writing a
shell or Python script). Submit a tabular file with 25 rows and three columns:
M, N, and elapsed time.


文章作者: SafePoker
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SafePoker !
  目录