Transcript Midterm

Midterm Review
October 23-27
Closed book
one hand written page of
notes of your own making
Perl Regular Expresions
 Extremely Powerful Text Processing.
 One of Perls most useful yet most misunderstood
features
 ‘=~’ indicates a regexp match
 if
 if
 if
 if
($var
($var
($var
($var
=~
=~
=~
=~
/BLAH/) – Match string
/^BLAH/) – Start of String
/BLAH$/) – End of String
/\w+/) – Any letters
 \w - Letters
 \d - Numbers
 \s - Whitespace
 . - Anything
Now search for the taxa
“hopper”
Whoa!! How do I search!!

print "line $_\n";

@words = split /\s+/, $_;

print "$words[0] \n";

print "$words[1] \n";

if($words=~/^hop|^fli/) {

print "found hopper or flick: dna
$words[1]\n";

} else {

print "not either";

}
metacharacters







\
Quote the next metacharacter
^ Match the beginning of the line
. Match any character (except newline)
$ Match the end of the line (or before newline at the end)
| Alternation
() Grouping
[] Character class
 By default, the "^" character is guaranteed to match only the
beginning of the string, the "$" character only the end (or before the
newline at the end), and Perl does certain optimizations with the
assumption that the string contains only one line. Embedded
newlines will not be matched by "^" or "$". You may, however, wish
to treat a string as a multi-line buffer, such that the "^" will match
after any newline within the string, and "$" will match before any
newline. At the cost of a little more overhead, you can do this by
using the /m modifier on the pattern match operator.
quantifiers
The following standard quantifiers are
recognized:
*
Match 0 or more times
+
Match 1 or more times
?
Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more
than m times
Character Class
 You can specify a character class, by
enclosing a list of characters in "[]",
which will match any one character
from the list. If the first character after
the "[" is "^", the class matches any
character not in the list. Within a list,
the "-" character specifies a range, so
that "a-z" represents all characters
between "a" and "z", inclusive.
Bracketing
 The bracketing construct "( ... )"
creates capture buffers. To refer
to the digit'th buffer use \<digit>
within the match. Outside the
match use "$" instead of "\".
Example
$var = "This Midterm";
$var =~ s/^([^ ]*) *([^ ]*)/$2 $1/;
Hashes
my %ancestors = (
grandfather => "gp",
gm => "grandmother",
great => "ggf",
);
my @mkey = keys %ancestors;
my @mval = values %ancestors;
print "key ", @mkey[1], ", value ", @mval[2], "\n";
print "gm = ", $ancestors{"gm"}, "\n";
Questions
•What does the listen() command do and how is it
related to the connection oriented nature of TCP?
•Is IP connection oriented?
•Is Ethernet connection oriented?
•Is TCP connection oriented?
•Is HTTP connection oriented?⁣
•You write() 100 bytes to the client end of a socket. On the
server side of the socket you issue a read() for 100 bytes.
The read() command returns 20 bytes. Why is this
happening?
Seven Layer Model
Application Email, FTP, www
Application
Presentation cinteger size, big endian
Presentation
Session
synchronization, name space
Session
Transport
reliability, congestion control
Transport
Routing
address
Network
Network
Network
Network
framing
errors
Data Link
Data Link
Data Link
Data Link
electrical
signals
Physical
Physical
Physical
Physical
Questions
What does the bind() procedure in the socket
library do? How does it interact with the TCP
and IP layers of the protocol stack.
What is a socket? How does a web server use
sockets to distinguish between different clients
that connect to it?
Web Operating System
Explain how the web could be the Operating System of the
future. In your answer, discuss features traditionally offered by an
OS and explain how these could be provided over the web.
Scheduling?
Service Small requests first?
File System?
URL
Access Control?
Security
Virtual Memory?
Cache Replacement
Questions
•What are the steps a web server must take in processing an HTTP
request?
•What are the differences between the way a web server deals with a
GET or POST cgi request.
•Is HTTP a stateless protocol?
•What are the 3 ways for a web application to maintain session state?
•URL Rewriting
•Hidden Fields
•Cookies
•Compare the pros and cons of each method.
•Explain how an HTTP cookie works. How does a perl application use
cookies to create persistant state.
•What does the SECURE keyword indicate for a cookie?
Questions
•How do signals work with threads and processes?
•Understand the implementation details and parameters for SysV
semaphores.
•Compare and contrast user level and kernel level threads.
•What are the differences between threads and processes?
•What does the fork() system call return?
•What system call would you use to determine file information?
•What system call would you use to change the stdout of a process?
•Why would you want to use a thread pool instead of a single thread
for serving requests from browsers?
•Why would you want to use a thread pool instead of spawning a
new thread for each request from a browser?
•From an Operating Systems perspective, what is the difference
between a process and a thread?