Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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)

In Unix/Linux, input and output are treated as files and referenced by the operating system using file descriptors. When you open a shell session, for example, three file descriptors are in use 0. standard input (stdin) 1. standard output (stdout) 2. standard error (stderr) By default, the command interpreter (shell) reads keyboard input from file descriptor 0 (stdin) and writes output to file descriptor 1 (stdout), which appears on the screen. As you explored in Lab 2, input/output can be redirected such that the operating system modifies the file descriptors to point to alternative, named files In this task, you will explore the use of file descriptors to read a file and print it to stdout using the system functions open, read, and close. Each of these has a man page accessible by typing man 2 and the function name. You are advised to find out more about how these functions work before beginning 1. Create a new source file named task4.c. Add a main function with argc/argv parameters and #include the following libraries o fcntl.h 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; I1 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. In Unix/Linux, input and output are treated as files and referenced by the operating system using file descriptors. When you open a shell session, for example, three file descriptors are in use 0. standard input (stdin) 1. standard output (stdout) 2. standard error (stderr) By default, the command interpreter (shell) reads keyboard input from file descriptor 0 (stdin) and writes output to file descriptor 1 (stdout), which appears on the screen. As you explored in Lab 2, input/output can be redirected such that the operating system modifies the file descriptors to point to alternative, named files In this task, you will explore the use of file descriptors to read a file and print it to stdout using the system functions open, read, and close. Each of these has a man page accessible by typing man 2 and the function name. You are advised to find out more about how these functions work before beginning 1. Create a new source file named task4.c. Add a main function with argc/argv parameters and #include the following libraries o fcntl.h 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; I1 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

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago