Question: please help me to complete the task4 code Deadlock occurs when all of the following apply: 1. Mutual exclusion condition 2. Hold and wait condition
please help me to complete the task4 code
Deadlock occurs when all of the following apply: 1. Mutual exclusion condition 2. Hold and wait condition 3. No pre-emption condition 4. Circular wait condition
Lecture5.pdf (2018)
1. Create a new source file named task4.c. Add a main function with argc/argv parameters and #include the following libraries: o stdio.h o stdlib.h o sys/stat.h o unistd.h Some of these should be familiar as we' ve used them many times. The unfamiliar ones are necessary for access to the aforementioned system functions. 2. Define a preprocessor macro named BUFFER SIZE. Assign it the value 1000 3. Inside main, declare the following two variables: int fd; I file descriptor char buffer 4. Use the open function to open the input file provided to the program as an argument. You only need to read the file, so the open function's access mode flags should reflect this. To retrieve the filename, use getopt with a suitable option (e.g. f filename)or manually parse the argc/argv values. 5. Use malloc to dynamically allocate a block of memory sized BUFFER_SIZE. The memory block should be assigned to the buffer pointer created in step 3. 6. If the memory was successfully allocated, read the contents of the file into it using the read function (take note of the function's return value). 7. Write the contents of the buffer, line by line, to stdout. 8. Deallocate the buffer memory block and close the file using the close function. Make use of Valgrind if necessary to confirm you have no leaks. 9. Compile the program using make/gcc. Run the program with the deadlock file (available on FLO) as its first and only argument. The expected output is as follows (Valgrind output Usage: /task4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
