Question: Write a C progrram, uni.c, which reads a given file using Unix open()/read() system calls as well as C fopen()/fgetc()/fread() functions and measure how long

Write a C progrram, uni.c, which reads a given file using Unix open()/read() system calls as well as C fopen()/fgetc()/fread() functions and measure how long it takes to finish reading the file.

****use gcc -Wall command

  • open: is a Unix system call that opens a given file.

  • read: is a Unix system call that reads a file into a given buffer.

  • close: is a Unix system call that closes a given file.

  • fopen: is a C standard I/O function that opens a given file.

  • fgetc: is a C standard I/O function that reads one byte from a file.

  • fread: is a C standard I/O function that reads a file into a given data structure.

  • fclose: is a C standard I/O function that closes a give file.

starting code

struct timeval start, end; // maintain starting and finishing wall time.

void startTimer( ) { // memorize the starting time gettimeofday( &start, NULL ); }

void stopTimer( char *str ) { // checking the finishing time and computes the elapsed time gettimeofday( &end, NULL ); printf("%s's elapsed time\t= %ld ",str, ( end.tv_sec - start.tv_sec ) * 1000000 + (end.tv_usec - start.tv_usec ));

}

int main( int argc, char *argv[] ) {

int typeofcalls; // validate arguments // // implementation

// Parsing the arguments passed to your C program // Including the number of bytes to read per read( ) or fread( ), and // the type of i/o calls used // implementation

// if (typeofcalls == 1) { // Use unix I/O system calls to // implementation

} else if (typeofcalls == 0) { // Use standard I/O // implementation }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!