edited by
212 views
0 votes
0 votes
Write a shell script that produces a file of sequential numbers by reading the last number in the file, adding $1$ to it, and then appending it to the file. Run one instance of the script in the background and one in the foreground, each accessing the same file. How long does it take before a race condition manifests itself? What is the critical region? Modify the script to prevent the race.

(Hint: use ln file file.lock to lock the data file.)
edited by

Please log in or register to answer this question.

Related questions

391
views
0 answers
1 votes
admin asked Oct 25, 2019
391 views
The objective of this exercise is to implement a multithreaded solution to find if a given number is a perfect number. $N$ is a perfect number if the sum of all ... by restricting the numbers searched from $1$ to the square root of $N.)$
342
views
0 answers
0 votes
admin asked Oct 25, 2019
342 views
A process can be put into a round-robin queue more than once to give it a higher priority. Running multiple instances of a program each working on a different ... processes, you should be able to grab a bigger share of the CPU this way.
745
views
0 answers
0 votes
admin asked Oct 25, 2019
745 views
Write a producer-consumer problem that uses threads and shares a common buffer. However, do not use semaphores or any other synchronization primitives to guard ... one number every minute because the I/O could affect the race conditions.
239
views
0 answers
0 votes
admin asked Oct 25, 2019
239 views
Rewrite the program of Fig. $2-23$ to handle more than two processes.