CS228 Midterm II -- The Cost of Indenting

  1. If I fail to indent my code properly
    1. The teacher will punish me.
    2. Nothing bad will happen.
    3. Real programmers don't; why should I?
    4. I can just indent it after I get the code right.
  2. Name a system call that servers generally use, and clients generally don't. _______________
  3. Consider your server program #2 (the TCP server).  If I disconnect the network cable, what system call will be the first to fail for your program? ________
  4. Circle all of the system calls that actually send packets over the wire when executed.
    1. accept
    2. listen
    3. fork
    4. connect
    5. bind
    6. reject
    7. gethostbyname
    8. write
  5. When a system call waits for an external to the program event to complete we say the system call 'hangs'.  For example, accept() waits for another program to connect, and there it 'hangs'.  Can read() hang?  _____________  Can write()? __________________
  6. My goal is to have the words "Indent or die' appear on any error.  What type of error would *NOT* generate the words'Indent or die'?

  7. char bug[100];
    int sock = socket( ..... );
    int fd = accept(sock, .... );
    int ret = read(fd, buf, 100);
    if (ret == -1) {
           perror("Indent or die");
           exit(1);
    }
  8. What will the following code do _________________________________________?
    while(fork() == 0) {
          cout << "I will always indent correctly\n";
    }
  9. In real life many web servers do not use the accept()/fork() paradym like your server.  Never  the less these servers can handle multiple connections at once, and never hang waiting for data.  How do they avoid having read() hang?





  10. It's Tuesday at 7:30am.  You are in the U.S.  Your code is indented properly.  You are under 18.  You are playing with MacPaint.  You are working for a company, and not attempting to make a profit.   Who can legally copy the new picture you just drew? (Note:  there is more than one answer.)




  11. Is the code for pine correctly indented?
    1. Yes, because they were good programmers
    2. No, because they are bad programmers.
    3. No, because it's a work in progress.
    4. My, aren't we fixated on indenting.
  12. Suppose I make a web page saying that David Bowie is a bad programmer because he never indents his code.  Further, I claim he sleeps with lizards and is fatter than Delta Burke.  Is this legal?  Why?
  13. Suppose I go to lookitup.com and search for the words 'automatic code indenter linux c++'.  It shows me 173 pages containing those words.  How did it get the list of pages to show?





  14. Under what circumstances is http/0.9 faster than http/1.0?
    1. The first time you load a page
    2. The second time you load a page.
    3. When the file is large
    4. When the file is small
  15. You send the command "HEAD /index.html http/1.0" to the web server.  Assuming the web server has that file, and implements http version 1.0, what is the first line of the reply?

  16. Suppose you try to connect to UDP port 80.  The web server is running on port 80.  What will happen?


  17. Which will receive more bytes per second, a request for a large file or a request for a small file?  ___________________
  18. What possible outputs can this program print if I run it on many different computers?
    main() {
        short a = 256;
        short b = ntohs(a);
        cout << "A = " << a << "B = " << b << endl;
    }
  19. What circumstances will make http/1.1 show the MOST improvement in performance over http/1.0?
  20. Suppose my computer is behind a router that stops all packets with the SYN bit set from coming to me.  In other words, no packet can arrive to me with the SYN bit set, but any packet I send can have the SYN bit set, and it will be transmitted successfully.  Can I run a web server?  ______ A web client. _________
  21. (Talker Question) Consider an enviornment that has very high latency and high bandwidth.  Which would transmit data faster,

  22.       a series of http requests in parallel or a series of http requests one after the other?  Why?