Advertisement
jdkipfer

Untitled

Mar 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. Programming Asiignment 3 help
  2.  
  3. 1. You are strongly recommended to create a dedicated directory cp367a3 for this assignment, and
  4. navigate to the directory cp367a3 where you want to store your work.
  5.  
  6. 2. How to zip your directory a3.
  7. under dirctory cp367a3
  8. zip -r cp367_a3_XXXX#### unixio.c a3output.txt systemcall.txt
  9. where XXXX#### is your Laurier's email ID
  10.  
  11. 3. You may refer to the following program design to complete the lab programming assignment 3.
  12. You'll need to Complete the main() function so that the program runs as required by adding missing pieces of code in your implementation.
  13.  
  14. #include <fcntl.h> // open
  15. #include <unistd.h> // read
  16. #include <sys/types.h> // read
  17. #include <sys/uio.h> // read
  18. #include <stdio.h> // fopen, fread
  19. #include <stdlib.h>
  20. #include <sys/time.h> // gettimeofday
  21.  
  22. struct timeval start, end; // maintain starting and finishing wall time.
  23.  
  24. void startTimer( ) { // memorize the starting time
  25. gettimeofday( &start, NULL );
  26. }
  27.  
  28. void stopTimer( char *str ) { // checking the finishing time and computes the elapsed time
  29. gettimeofday( &end, NULL );
  30. printf("%s's elapsed time\t= %ld\n",str, ( end.tv_sec - start.tv_sec ) * 1000000 + (end.tv_usec - start.tv_usec ));
  31.  
  32. }
  33.  
  34. int main( int argc, char *argv[] ) {
  35.  
  36. int typeofcalls;
  37. // validate arguments
  38. // // implementation
  39.  
  40. // Parsing the arguments passed to your C program
  41. // Including the number of bytes to read per read( ) or fread( ), and
  42. // the type of i/o calls used
  43. // implementation
  44.  
  45. //
  46. if (typeofcalls == 1) {
  47. // Use unix I/O system calls to
  48. // implementation
  49.  
  50. } else if (typeofcalls == 0) {
  51. // Use standard I/O
  52. // implementation
  53. }
  54.  
  55. return 0;
  56. }
  57.  
  58. 4. After you finish your program, you can do the following tests to check if your program works correctly.
  59.  
  60. For the testing purpose, you first need to create a file with a specific size, for example, using the truncate utility. As shown below, you can shrink or extend the size of a file named filename to 1M by using truncate. If the filename doesn't exist, it will be created
  61.  
  62. truncate -s 1M filename
  63.  
  64. Learn the syntax of the truncate utility using the man command
  65. man truncate
  66.  
  67. - compile and test
  68.  
  69. $gcc -o unixio unixio.c
  70. $./unixio filename 1024 1
  71.  
  72. - batch test: create a bash shell script named t.sh with following content:
  73.  
  74. #!/bin/bash
  75. buffersize=(1 256 512 1024 2048 2096)
  76. ## Start testing
  77. for value in ${buffersize[*]}
  78. do
  79. ## Testing Unix I/O system calls
  80. tcommando="./unixio filename $value 1"
  81. eval $tcommando
  82. ## Testing C calls
  83. tcommando="./unixio filename $value 0"
  84. eval $tcommando
  85. done
  86. ## Testing is done! :-)
  87.  
  88. Note that you need to set up proper permissions on the above testing script before you execute the script, for example,
  89. chmod +x script.sh
  90. , which allows everyone to execute the script.
  91.  
  92. Then, enter
  93. ./t.sh
  94.  
  95. Assume you have successfully executed your program and your program passes your tests, please record your execution output when reading a file by 1, 256, 512, 1024, 2048, and 2096 bytes and save your execution output into a file named a3output.txt by entering
  96. ./t.sh>a3output.txt
  97.  
  98. Also, you need to test the following abnormal situations to see whether your program is robust to handle these abnormal situations
  99. • Invalid number of arguments
  100. • A file argument that does not exist
  101. • Invalid number of bytes (or buffer size) to read per read( ) or fread( ), for example, negative number of bytes
  102. • The type of I/O calls entered is invalid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement