Answered step by step
Verified Expert Solution
Link Copied!

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 file(new.sh) that will create a new directory and fill it with 20-30 files, each containing 1000 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 file3.txt for example:
12544
24616
22273
3943
7355
7340
4708
16990
9518
6003
10807
15770
16764
26935
15964
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 25 random files and we test with 5(5 active threads), the output will be as follows;
Thread 1 has found 6454 primes in file1.txt
...
Thread 5 has found 23935 primes in file2.txt
Please write the program in C.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions

Question

Enumerate the benefits of depositary receipts to the issuers.

Answered: 1 week ago

Question

develop your skills of project planning.

Answered: 1 week ago

Question

evaluate different research strategies;

Answered: 1 week ago