Suppose we execute a long-running program that slowly


Suppose we execute a long-running program that slowly generates output that is redirected to a file or pipe, as in this example:
$ longrunner | grep str

One problem with the above scenario is that, by default, the stdio package flushes standard output only when the stdio buffer is filled. This means that the output from the longrunner program will appear in bursts separated by long intervals of time. One way to circumvent this problem is to write a program that does the following:

a) Create a pseudoterminal.

b) Exec the program named in its command-line arguments with the standard file descriptors connected to the pseudoterminal slave

c) Read output from the pseudoterminal master and write it immediately to standard output (STDOUT_FILENO, file descriptor 1), and, at the same time, read input from the terminal and write it to the pseudoterminal master, so that it can be read by the execed program.
Such a program, which we'll call unbuffer, would be used as follows:
$ ./unbuffer longrunner | grep str

Write the unbuffer program. (Much of the code for this program will be similar to that of Listing 64-3.)

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Suppose we execute a long-running program that slowly
Reference No:- TGS01402279

Expected delivery within 24 Hours