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 16:50
Consider a slotted aloha system, where the time slot equals the fixed duration of each packet. assume that there are 4 stations a,b,c,d sharing the medium. (a) stations a,b,c,d receive one packet each from higher layers at times 1.3, 1.5, 2.6,5.7 respectively. show which transmissions take place when, according to the slottedaloha protocol; describe all transmissions until all four packets have been successful.when needed, each station has access to the following sequence of random number, provided by a random number generator and drawn uniformly between 0 and 1: (1) station a draws numbers: 0.31, 0.27, 0.78, 0.9, 0.9, 0.11, 0. (2) station b draws numbers: 0.45, 0.28, 0.11, 0.83, 0.37, 0.22, 0. (3)station c draws numbers: 0.1, 0.2, 0.3, 0.4, 0. (4) station d draws numbers: 0.36, 0.77, 0.9, 0.1, 0.1, 0.1, 0.1, 0. (b) in slotted aloha, a station transmits in each time slot with a given probability. what probabilities would you assign to each of the four stations so as to: (i) maximize the efficiency of the protocol? (ii) maximize fairness among the four stations? (c) will the efficiency increase or decrease if we modify slotted aloha as follows: (i) get rid of slots and allow stations to transmit immediately? (ii) implement carrier sensing? (iii) implement collision detection? (iv) implement collision avoidance?
Answers: 3
question
Computers and Technology, 23.06.2019 15:30
1. ask the user how many questions are in the quiz. 2. ask the user to enter the key (that is, the correct answers). there should be one answer for each question in the quiz, and each answer should be an integer. e.g., 34 7 13 100 81 3 9 10 321 12 might be the key for a 10-question quiz. you will need to store the key in an array. 3. ask the user to enter the answers for the quiz to be graded. there needs to be one answer for each question. note that these answers do not need to be stored; each answer can simply be compared to the key as it is entered. 4. when the user has entered all of the answers to be graded, print the number correct and the percent correct. 5. add a loop so that the user can grade any number of quizzes with a single key. after the results have been printed for each quiz, ask "grade another quiz? (y/n)." note: you only have one array (the key). you are not creating a new key for each set of quiz answers.
Answers: 3
question
Computers and Technology, 24.06.2019 02:30
Write the pseudo code for this problem based on what you learned from the video. the purpose is to design a modular program that asks the user to enter a distance in kilometers, and then converts that distance to miles. the conversion formula is as follows: miles = kilometers x 0.6214
Answers: 3
question
Computers and Technology, 24.06.2019 05:30
Why is hard disk space important to an audio engineer? why are usb ports and firewire ports useful for an audio engineer? explain in 2-3 sentences. (3.0 points) here's a list of different audio software: ableton live apple inc.'s garageband apple inc.'s logic studio digidesign's pro tools propellerhead sofware's reason sony creative software's acid pro steinberg cubase steinberg nuendo choose one of the software programs listed above, and then go to that software program's web site. read about what the software program is used for, and then write 4-5 sentences about what you learned. (10.0 points) which type of software license is the most limiting? why? explain in 2-3 sentences. (3.0 points) when sending a midi channel voice message, how can you control the volume of the sound? explain in 2-3 sentences. (4.0 points)
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, 02.10.2019 18:40
question
Mathematics, 02.10.2019 18:40
Questions on the website: 13722361