Topic: unix c programming-Testing for Prime Numbers
Write a concurrent program that tests for prime numbers. The program should be able to create more than two processes. Each process should have the following functionalities.
Each process tries to read a number n from a file named 'number.txt'. Then, the process writes n+1 back to 'number.txt' for next process.
After fetching a number from 'number.txt', the process should test whether this number is a prime number or not. If this number is a prime number, the process will append this prime number to a file named 'prime.txt', otherwise, this number is appended to a file named 'nonprime.txt'.
After testing 100 numbers, the process should terminate.
If there are p processes and the starting number in 'number.txt' is s, then the numbers from s to s+100*p will be tested.
'prime.txt', 'nonprime.txt', and 'number.txt' are shared resources. The processes in your program should have mutual exclusive access to these two files. You have to test your program many times to make sure that mutual exclusion is implemented.
Your program should use the UNIX semaphore. The P(), V(), open_sem(), set_semvalue(), del_semvalue() can be found in the following program files mysem.c and mysem.h. An example of using these semaphores operations can be found at sem2.c.
PLEASE SOMEBODY HELP! I HAVE HARD TIME !!!!!!1