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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 03:00, tay9122
Jason, samantha, ravi, sheila, and ankit are preparing for an upcoming marathon. each day of the week, they run a certain number of miles and write them into a notebook. at the end of the week, they would like to know the number of miles run each day, the total miles for the week, and average miles run each day. write a program to them analyze their data. your program must contain parallel arrays: an array to store the names of the runners and a two-dimensional array of five rows and seven columns to store the number of miles run by each runner each day. furthermore, your program must contain at least the following functions: a function to read and store the runners’ names and the numbers of miles run each day; a function to find the total miles run by each runner and the average number of miles run each day; and a function to output the results. (you may assume that the input data is stored in a file and each line of data is in the following form: runnername milesday1 milesday2 milesday3 milesday4 milesday5 milesday6 milesday7.)
Answers: 3
image
Computers and Technology, 23.06.2019 09:30, Cocco
You have been supporting csm tech publishing's windows server 2016 server network for over a year. the office has two windows server 2016 servers running active directory and a number of other roles. management has informed you that a small sales office is opening in the same building three floors up. the sales manager wants to install a sales application on a server located in the sales office. this server will have limited physical security because there's no special room dedicated for it, which means it will be accessible to non-it personnel and visitors. you're considering installing windows server 2016 server core on the new server because accessing its console regularly probably won't be necessary, and this server will be managed from one of the other csm tech publishing servers. what are the benefits and drawbacks of using server core for this branch office? what are some things you should do to set up this server management environment?
Answers: 1
image
Computers and Technology, 23.06.2019 23:40, lexiecooley
4. what is the reason for including the following code snippet in the header file animal. h? #ifndef animal_h #define animal_h class animal { public: animal(); animal(double new_area_hunt); void birth(); void hunt(double new_area_hunt); void death(); double get_area_hunt() const; private: double area_hunt; }; #endif
Answers: 3
image
Computers and Technology, 24.06.2019 00:30, lovemusic4
Setting up a home network using wireless connections is creating a a. vpn b. lan c. wan d. mini-internet
Answers: 2
You know the right answer?
ONLY using POSIX calls read(), write(), open(), close(), and pthreads library (no c++ I/O library or...

Questions in other subjects: