Question: We will write a C program using threads and semaphores to implement critical sections. There's a shell script file ( new . sh ) that
We will write a C program using threads and semaphores to implement critical sections. There's a shell script filenewsh that will create a new directory and fill it with files, each containing random integers. We must design a program to accept two parameters from the command line, the directory containing generated txt files myDir and the number of simultaneously active threads threadNumber The program aims to use threads to compute the number of prime numbers in each file and print thread by thread. The number of active threads at a time is to be limited to threadNumber.
Use a semaphore mutex to limit the number of simultaneously active threads threadNumber Create threads whenever an active thread terminates.
This is filetxt for example:
The program is to use threads to compute the number of prime numbers in EACH file and print thread by thread with the threadNumber we specify from the command line. For example, let's assume we have random files and we test with active threads the output will be as follows;
Thread has found primes in filetxt
Thread has found primes in filetxt
Please write the program in C
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
