阅读背景:

分叉过程,读取文件但不显示其内容

来源:互联网 

I have the following code where I have to enter 2 arguments as an input where: The 1st argument is a number. If this number is multiple of 2, then 15 child processes will be created with fork. If the number is multiple of 3, 10 processes will be created. If the number is multiple of 5, 7 processes will be created. The 2nd argument is a file where its size (in bytes) will be divided into the number of processes created and each child process is going to read one part of the file, they save that part into a variable and finally the parent shows all the text in that variable. For example, I run the program with ./p 5 /home/directoryFile.c. So I'm having 7 child processes and let's say the filesize is 700 bytes. That means every child process should read 100 bytes, they save it into a variable (appending the content) and finally the parent shows all the content together. The problem is that the variable textToSend that should show all the content in the parent doesn't show anything... I believe there should be a problem with the sprintf line in the child.I have the following code where I have to enter




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: