FAQ

for

Project 1 -- Standard I/O and Device Drivers

Q. What is that time we need to use in the project??IS that the "time_t objects"or the "System Times".I couldn't get any time using the system times" and with the time command I got the difference between start of process and the end.(is that what we need to do??

A. You don't want to measure the entire time it takes for the process to run, only the time it takes to send the file contents to standard out or the new named file. In other words, the structure of your program will be roughly:

1a. Open the file to read it.
1b. Read the file.
1c. Close the file.

Repeat 100 times:
2a. Open the file to write it (or, for those versions using standard out, do nothing).
2b. Write the file 1000 times.
2c. Close the file (or, for those versions using standard out, do nothing).

3. Send the data collected to standard error.

Of these things, the only one you want to measure the time on is 2b. You want to do this just as though you were able to look at a clock on the wall right before 2b starts and just after 2b ends, then calculate the difference between them. Of course, you won't be able to use a wall clock, so you will use the times system call that I referred to in your assignment, to find the time just before executing 2b, then use times again to find the time just after doing 2b.

Note that times doesn't use the time_t data type, it uses clock_t.


Q. I don't know how to print directly from Unix.SInce we need to know the printer name or the location right?/and I don;t have any idea of how to print from UNIx in all the labs.

Most systems will be configured with a default printer. The lab in CS is no exception. Without specifying a printer, you can use an appropriate command such as lp or lpr to send a file to the default printer. The format for this is:

% lp <filename>

where <filename> is replaced by the name of the file you wish to print. For example:

% lp myprogram.c

would print out the file myprogram.c on the default printer. In the CS lab, this will be the printer there in the room which is named gpel. If you want to print to another printer, you can specify that printer using the appropriate flag (-d for lp, -P for lpr) as given in the man pages for these commands. You can also cancel print jobs before they are printed using cancel or lprm.


Q. I don't understand what you are asking for when you say to write to "standard error."

We will cover the reason that standard error exits and how it differs from standard out later in this course. For this assignment, you can treat it as though it were a second standard out with a different name. So, to write to it, you could use fputs("This will be printed.\n", stderr); or fprintf(stderr, "Hello world.\n");, just as you could use fputs("This will be printed.\n", stdout); or fprintf(stdout, "Hello world.\n"); to write to standard out.

By default, standard error points to the screen, just as standard out does. However, like standard out, standard error can be redirected elsewhere. Further, because standard out and standard error are redirected separately, they can be redirected to different files, or one can be redirected but not the other. How you redirect standard error varies from one shell to another. For example, using the Bourne Again Shell (bash), you can redirect standard err using 2>. For example:

$ myprogram > myoutfile 2> myerrfile

would capture the standard output of myprogram in a file called myoutfile and the standard error of myprogram in a file called myerrfile.