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 05:00
This program will store roster and rating information for a soccer team. coaches rate players during tryouts to ensure a balanced team. (1) prompt the user to input five pairs of numbers: a player's jersey number (0 - 99) and the player's rating (1 - 9). store the jersey numbers in one int vector and the ratings in another int vector. output these vectors (i.e., output the roster). (3 pts) ex: enter player 1's jersey number: 84 enter player 1's rating: 7 enter player 2's jersey number: 23 enter player 2's rating: 4 enter player 3's jersey number: 4 enter player 3's rating: 5 enter player 4's jersey number: 30 enter player 4's rating: 2
Answers: 1
question
Computers and Technology, 22.06.2019 06:30
Plz 40 points what are raster vectors? a bitmap image a vector file a type of printing press a small projector
Answers: 1
question
Computers and Technology, 22.06.2019 12:40
How do i get the most points, without any effort?
Answers: 2
question
Computers and Technology, 23.06.2019 02:00
Arecipients list has been loaded into a document. which commands should be clicked in order to filter the list so that letters will not be printed for recipients who live in a certain state? mailings tab, start mail merge, select recipients, type new list, then insert only contacts from the desired states mailings tab, rules, select recipients, use existing list, then choose a recipients list that includes only contacts in certain states mailings tab, select recipients, use existing list, rules, fill in, then type in certain states mailings tab, rules, skip record select “state” under field name, then type in the state name under “equal to”
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
question
Mathematics, 01.07.2019 14:10
Questions on the website: 13722361