subject

ONLY using POSIX calls read(), write(), open(), close(), and pthreads library (no c++ I/O library or cin/cout), Make a program that takes an input file from user input, opens it, and does the following: 1) Use the main thread to read the input file of 10,000 unsorted integers (1 line per integer in character format) from the beginning of the file to the end of file. While reading the input file you collect the start and end offsets of each of the 10 input file chunks of 1,000 lines each. Each file chunk obviously has 1,000 numbers.
The main thread writes 10 lines of file chunk information in the following format for each line:
Main Output: \t logical thread number \t start offset \t end offset \n
2) The main thread creates 10 worker pthreads (one pthread per file chunk as in (a)). Each pthread runs a function called computeMin (which you will also write) to take the start and end offsets and a file chunk number (0,1,2,...,9), read the input file, and determine the minimum integer of the file chunk. Each worker pthread saves this minimum in the chunk to a global array of 10 integers at the element number given by the file chunk number.
Each worker pthread itself writes one line of output in the following format for each line:
Worker Output: \t logical thread number \t start offset \t end offset \t minimum integer \n
3) The main thread will determine the global minimum (that is, the minimum of the global array of 10 integers).
The main thread writes one line of final output in the following format:
Main Output: The global minimum = \t PLACE THE ACTUAL GLOBAL MINIMUM HERE \n
This is how I'm opening file from user
int main(int argc, char *argv[]){
char buffer[64];
const char *filename;
if(argc != 2){
pprintf("Enter input file: ");
ssize_t l = read(STDIN_FILENO, buffer, 64);
buffer[l-1] = '\0';
filename = &buffer[0];
}
else{
filename = argv[1];
}
int inFile = open(filename, O_RDONLY);
and I got a function to help me print without using printf
unsigned int pstrlen(const char *s)
{
unsigned long length = 0;
while('\0' != s[length] && UINT_MAX != length)
length++;
return length;}
void pprintf(const char *s)
{
write(STDOUT_FILENO, s, pstrlen(s));
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 03:00
You install teamviewer on your workstation at home so that you can ac ess it when on the road. how can you be assured that unknown users cant access your computer through team viewer?
Answers: 2
question
Computers and Technology, 22.06.2019 04:00
Which spereadsheet type will determine how well a bussiness has done over the past year
Answers: 1
question
Computers and Technology, 22.06.2019 08:40
What are the three parts to physical security standards for various types of army equipment and the risk level
Answers: 2
question
Computers and Technology, 23.06.2019 05:00
In cell b18, enter a formula to calculate the amount budgeted for meals. this amount is based on the daily meal allowance and the total travel days (# of nights+1).
Answers: 1
You know the right answer?
ONLY using POSIX calls read(), write(), open(), close(), and pthreads library (no c++ I/O library or...
Questions
question
Mathematics, 27.05.2020 19:59
question
Mathematics, 27.05.2020 19:59
question
History, 27.05.2020 19:59
question
Mathematics, 27.05.2020 19:59
question
Mathematics, 27.05.2020 19:59
question
Health, 27.05.2020 19:59
Questions on the website: 13722363