Question: Write a C program, 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 program, 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 timet= %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

3.38 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To create a C program unic that measures the time it takes to read a given file using both Unix open... View full answer

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 Operating System Questions!