Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started