-
Notifications
You must be signed in to change notification settings - Fork 10
/
all CS241 questions except quiz 1 and 5.txt
1356 lines (912 loc) · 37.2 KB
/
all CS241 questions except quiz 1 and 5.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[quiz2]
What does close(1); open("file") do?
pipes output into a file
What does the following program do and how does it work?
sleepsort - waits for (size of value) ms and returns values in a size-based order
What does the child inherit from the parent? What does it not?
a deep copy of everything EXCEPT its PID, signals, or alarms
How do I wait for my child to finish?
use wait() or waitpid()
Can I find out the exit value of my child?
sort of - only the lowest 8 bits
How do I start a background process? (Hint: BF4's Active Radar)
Don't wait() for them!
What would be effect of too many zombies?
system becomes unstable
What does the system do to help prevent zombies?
if a process terminates, its children are assigned to and waited on by an OS process
What are 'zombies'?
terminated processes that clutter the kernel process table
How do we kill zombies?
wait() on them
How do I send signals programmatically to a process?
using kill() #hacking
How do I send a user-defined signal? Terminate signal?
SIGUSR#; SIGTERM
Why should I use the signal symbols not the constants?
they vary across platforms
What happens if malloc fails?
it returns NULL
What does typedef int foo do? What is this especially useful for?
allows me to use "foo" instead of "int"; structs
Variables declared outside of functions are _________ and _________?
initialized and immortal
What is a major gotcha with ctime()?
it returns a ptr to a scratch-pad buffer (which changes if it's called again)
What is the sizeof() of type[]?
sizeof(type) * array_len
[quiz3]
Can a new thread join on the original main thread?
yes!
What is external fragmentation?
when memory outside of blocks is inconsistently free/taken
What is internal fragmentation?
when memory within blocks is inconsistently free/taken
What is fragmentation and why is it a problem?
we try to fit as many different-sized blocks into memory as we can while minimizing block moving
How does a best-fit memory policy allocate memory
use free block closest to target size
How does a worst-fit memory policy allocate memory
use blocks at the beginning of largest available free chunk
How does a first-fit memory policy allocate memory
use first free block that works
What are differences between malloc/realloc/calloc? Spot errors in using them.
malloc - create; realloc - expand if you can else create; calloc - malloc with zero initialization
What would c/m/re-alloc do if it cannot satisfy the memory allocation request?
Return NULL
What does sbrk do and why?
allocate more heap memory
Do pthreads share stack(s)?
no
Do pthreads share heap(s)?
yes
What does sbrk() do to ensure OS security?
zeroes out new memory to prevent programs reading zombies’ data
Is there anything wrong with “realloc(array, (size ^ 2) * SZ_OF_ELEM)”?
yes - realloc may move the array, so we need an “array = “
What are explicit free lists?
free blocks point to other free blocks as a doubly linked list
What do boundary tags indicate? Why is this information useful?
size of previous blocks; helps us coalesce adjacent free blocks
What are implicit free lists?
store block size and free state on the block itself (regardless of its type)
In implicit free lists, where is free state stored? Why can we do this?
as SIZE’s last bit; an aligned SIZE is a multiple of 4
What is a segregated free list?
blocks are grouped by size
What is a buddy allocator?
a segregated free list with sizes that are powers of 2
What are the pros/cons of buddy allocators?
fast but fragment a lot
How can boundary tags be hacked?
evil buffer overflows can overwrite them
What prevents me from reading someone else’s memory (i.e. what sends me the SIGSEGV)?
virtual memory
What are pages?
units of memory shared between RAM and disk
How can we communicate with other pthreads?
passing/receiving a single void ptr
What is pthread_join()?
pthread version of wait()
What is pthread_exit() the same as?
returning from a thread
What happens if we have too many stacks?
program crashes
What happens if we have too many heaps?
Gotcha! (We can only have 1)
What is the hierarchichal structure of pthreads?
they’re all equal
What does pthread_cancel() do?
kills a pthread either on a major event or immediately
Why do we usually avoid pthread_cancel()?
it’s too forceful
What is the primary difference between returning and pthread_exit’ing?
returning from main kills the program; pthread_exit() just stops the main thread
When does pthread_exit() terminate a program?
when all pthreads are dead
When does return terminate a program
when returning from main
What happens if we don’t join on pthreads?
pthread table can overflow and crash the program
What happens if two threads try to pthread_join another one?
undefined behavior
How do we protect against thread-unsafe constructs in C?
using locking mechanisms
Is using strtok()/asctime()/etc. in multiple threads dangerous? If so, why?
yes - they use a static buffer shared between threads
What function do we use to create a pthread?
pthread_create()
Can threads share heap variables (assuming they exist)?
yes
Can threads share stack variables (assuming they exist)?
yes
What are the pros/cons of threads vs. processes?
threads have easier communication but less security
What does exit() effectively do?
return a specified value from main()
What happens when we fork a process with multiple threads?
the threads are copied
What are the arguments to pthread_create? (IN ORDER!)
&thread id, attribs, function, data ptr
What is a common gotcha when using pthread_create?
it returns 0 on success - NOT a new thread ID
What are the 4 ways a thread can be terminated?
return from main, return from thread, kill thread, kill process
What does it mean if pthread_create throws error EAGAIN?
too many threads (or zombies)
Which is faster, creating a thread or a process?
creating a thread
What happens if two threads try to pthread_join() each other?
EDEADLK
What does SIGALRM do by default?
kill program
What happens if 2 threads join the same other thread?
undefined
[quiz4-part1]
What is a Critical Section?
a piece of code that cannot support multiple threads
Does merely incrementing a variable create a critical section?
yes!
How do I prevent multiple threads from entering a critical section?
use a mutex
What is pthread_mutex_destroy() used for?
cleaning up after unlocked mutexes
What happens when you do illogical things with pthread_mutex'es? (e.g. destroying a destroyed mutex)
undefined behavior
If a mutex is locked, which threads does it stop?
any that try to lock it
What is PTHREAD_MUTEX_INITIALIZER?
a default-initialized mutex constructor
What's the difference between PTHREAD_MUTEX_INITIALIZER and pthread_mutex_init()?
only for global variables, faster w/less error checking
What happens to mutexes when fork()-ing? What's the gotcha?
they are copied; locking M on one process doesn't lock the other's M
If thread T locks a mutex, who can unlock it?
only thread T
Can we use multiple mutex locks? If so, how are they commonly split up?
yes; one lock per shared data structure
What should we watch out for when using multiple mutex locks?
locks must be conceptually correct
Is there any overhead in calling pthread_mutex_lock()/unlock()?
a tiny bit
What is a counting semaphore?
a construct that limits the # of threads in a code section
What two operations does a counting semaphore support?
sem_wait(), sem_post()
What does sem_wait() do?
wait until count > 0, decrement it, and return
What does sem_post() do?
increment the semaphore and return
A counting semaphore keeps track of what?
number of AVAILABLE threadspots in a critical section
What is the minimum "count" value of a counting semaphore (ever, not just on init)?
0
What kind of semaphores does CS241 use? What popular OS doesn't support them?
named semaphores; Mac OSX
Can I call sem_wait() and sem_post() from DIFFERENT threads on the SAME semaphore?
yes (duh)
Why do we use mutexes instead of 1-count semaphores?
mutexes are faster
Can we use semaphores inside a signal handler? If so, why is this useful?
yes; allows us to release a thread that calls handler-unsafe functions
Is using signal() in a multithreaded program a good idea? If not, what do we use instead?
no; sigaction
What does double-locking do to a mutex of type PTHREAD_MUTEX_NORMAL?
DEADLOCK!
What does double-locking do to a mutex of type PTHREAD_MUTEX_DEFAULT?
undefined behavior
What does a mutex of type PTHREAD_MUTEX_RECURSIVE resemble?
counting semaphore
[quiz4-part2]
What does pthread_mutex_trylock() do?
pthread_mutex_lock without the waiting
What happens when a thread waiting for a mutex is signalled?
nothing
What does it mean if the second argument of sem_init() is 0? Non-0?
semaphore is private to its process; semaphore is shared between processes
What happens if we initialize an already-initialized semaphore?
undefined behavior
In general, what happens to a semaphore's "count" value if a semaphore function fails?
nothing
What does sem_trywait() do?
same thing as sem_wait, but returns an error instead of waiting
What makes an operation atomic?
it happens in an indivisible step
What restrictions exist when making a copy of a pthread_mutex_t?
the copy is broken!
What is the pthread equivalent of sleep? Why do we use it?
pthread_yield(), to reduce CPU waste while locking
What are the desired properties of solutions to the Critical Section Problem?
mutual exclusion, bounded wait, progress
What is the meaning of "bounded wait"?
a task can never have an infinite waiting time
What is the meaning of "progress"?
we shouldn't wait unless we have to
What is Petersen's solution?
HI my flag, turn = ME, wait(your flag = LO || turn = YOU), METHOD, LO my flag
What is Dekker's solution?
HI my flag, wait(your flag HI and turn YOU), LO my flag, wait(turn = YOU), HI my flag, turn = YOU, LO my flag
Why is it a bad idea to implement Peterson's algorithm in C?
compilers can reorder instructions
What is XCHG?
atomic CPU instruction that swaps a register and a memory location's values
What CPU instruction is useful when implementing a mutex?
XCHG
What do condition variables do?
let groups of threads sleep until poked
How do you poke threads under a condition variable?
pthread_wait_signal()
What happens if you only wake a single thread in a multi-thread condition variable?
the OS decides which thread to wake up
What is Spurious Wakeup? How is it mitigated?
a waiting thread can be accidentally awoken; wait until a given continuation condition is true
Does pthread_wait_signal() have anything to do with POSIX signals?
no!
How do I wake up all the threads in a condition variable?
pthread_cond_broadcast
What does pthread_cond_wait() (with mutex m) do?
unlock m, wait for pthread_cond_signal, lock m
Why are spurious wakes useful?
signals can get missed if a race condition occurs, and they're faster than avoiding race conditions
What must be done before calling pthread_cond_wait?
lock its mutex
What are the two concerns of advanced (i.e. real life) counting semaphores?
queue for fairness, works across processes
[quiz6-deadlock]
What are Coffman conditions conditions for?
deadlock
What are the 4 conditions for deadlock?
mutual exclusion, circular wait, hold/wait, no pre-emption
What must happen for circular wait to occur?
a resource allocation graph has a cycle
What is meant by hold and wait?
a process is holding some resources and waiting for others
What is meant by no preemption?
once a process has a resource, it can't let go of it
What is Livelock?
processes continually swap resources in an attempt to stop deadlock
How do we check for deadlock potential using a Resource Allocation Graph? (Hint: LOL REDDIT)
check for circular dependency
[quiz6-virtualMemory]
What are the 2 main advantages of Virtual Memory?
keeps processes safe from others, allows memory relocation
What is the MMU?
CPU part that converts virtual address to physical one
When does the MMU interrupt the CPU (if at all)?
when segfaulting
Why are pages useful?
they take (many) fewer bits to address than raw memory
What is a page?
block of virt mem
How big are pages on a typical Linux OS?
4KB (2^12 bytes)
How many pages does a typical Linux OS use? (HINT: Show equation!)
4 GB / 4 KB = (2^10)^2
What is a frame?
physical memory block with the size of the virtual memory block
What is a page table?
a map between pages and frames
What data structure do the simplest page tables use?
array
Why do naive page tables (arrays) work on 32 bit architectures, but not 64 bit ones?
64 bit addresses are bigger, and take orders of magnitude more space (~40 petabytes) to store
What is the purpose of the offset?
refer to a specific address within a frame
How are block indexes/offsets stored within a memory address? (Hint: think CS398)
block index, then offset
What are Multi-level page tables? What problem do they solve?
page tables of page tables; 64-bit page table size
Do unoptimized page tables slow down memory access? If so, what optimizations do we make?
yes - a lot; TLB (cache of table lookups)
What determines how useful the TLB is to a program? How many programs is this useful for?
whether or not its memory accesses repeat a lot; most
Can frames be shared between processes?
yes
Can we specify permissions (e.g. read, write, both) for memory blocks? If so, where are these stored?
yes, page table
What are the two ways processes can share memory?
commonly-needed read only memory, mmap()
When can a process use mmap()?
when talking to its children
What is the purpose of the Dirty bit? Where is it stored?
determine if a page needs to be updated on disk, page table
What is the purpose of the NX bit? Where is it stored?
enables DEP, page table
[quiz6-pipes]
What are pipes?
POSIX constructs that allow data shipment between processes
Are POSIX pipes directed (one- or two-way)?
yes (one-way)
Who can we communicate to with pipes?
our children(?)
How can we use pipes to talk to child processes?
pipe(), then fork()
Can we use a pipe to communicate within a process? If so, what's a potential danger we must avoid?
silly idea but we can; deadlock by filling the pipe buffer
Why must we terminate our pipe transmissions?
processes wait on pipes until told to stop
What are the 3 ways we can terminate a pipe transmission?
fflush(), printf("\n"), look for a terminal character
What is the purpose of fdopen()?
converts file descriptors into FILE ptrs, which lets us use *f functions
Can we use open() or fopen() on a pipe instead of fdopen()? If so, why do we usually avoid it?
yes; it's slow
What is meant by "Hungry Hungry Pipes"?
pipes generally wait for "food" until told to stop
Under what conditions does C automatically flush a pipe [buffer]?
when its full, when its closed
Which streams in C are line buffered (if any)?
only terminal streams
If we want to have two-way communication with pipes, how many pipes must we create?
2
When does a process receive a SIGPIPE signal?
when writing to a pipe with no listeners
If everyone but the child closes a pipe's read end and the child tries to write to it, is SIGPIPE generated? What is the common habitual fix?
no!, close unused ends immediately after fork()
When is an unnamed pipe freed by the OS?
when all dependents have exited
[quiz6-files]
How do we tell the size of a file? (actual code)
fseek(f, 0, SEEK_END); return ftell(f);
How do we move to an arbitrary position n within a file? (actual code)
fseek(f, n, SEEK_SET);
What function sets the position within a file?
fseek()
[quiz6-manpages]
What C type is the first argument of most of f* functions? (Hint: NOT a file descriptor!)
FILE ptr
What units of size does fseek() use?
bytes
How is the position within a file after fseek() computed?
add arg_2 bytes to arg_3
What are the special values of arg_3 for fseek()? What does each represent?
SEEK_SET - beginning of file, SEEK_CUR - current pos, or SEEK_END - end of file
What does ftell() do?
returns current position in a file
What are fgetpos() and fsetpos()? Why are they useful on non-UNIX systems?
same as ftell() and fseek(); some of these systems don't support ftell()/fseek()
What do most f* functions return on success? On failure? (Hint: this messes with if statements)
0 if successful; -1 otherwise
What does rewind return? (Hint: it's not "0 if successful. -1 otherwise")
nothing
What does fflush() do?
flush a stream
How do we flush ALL streams within a process?
fflush(NULL)
What does fflush() return on success? On failure? (Hint: this is 50% gotcha)
0, EOF
What happens to a file descriptor if its fdopen'ed file ptr is closed?
it too is closed
What is the result of using fdopen() on a shared memory object?
undefined
[quiz7-errorHandling]
What is errno and when is it set?
error indicating value set when a system call fails
How is errno handled in threads?
each has their own copy
When is errno reset automatically?
never!
Is it a good idea to change the value of errno for later use?
no
When handling a signal, what should we do to errno?
preserve its value
What does strerror() do?
print out message for a particular errno value
What does perror() do?
prints out first variable (if possible), then the most recent error message
Is strerror() thread safe? If not, what can we use instead?
no, strerror_r()
What does EINTR mean?
action was interrupted
If a system call has an EINTR, what should we do?
retry it
What is the gotcha with EINTR and read()/write() on Linux?
they auto-restart on disk ops, but EINTR on network ones
What is the rule of thumb as to which calls can be interrupted?
slow, blocking ones are interruptible, others are not
What two things can happen if a signal handler is invoked during a system call?
call fails with EINTR, call auto-restarts
What function do we use to create a signal handler?
sigaction()
What is the SA_RESTART flag for signal handler creation?
change *SOME* EINTR fails to auto-restarts
Does SA_RESTART work for all calls?
no!
[quiz7-networking1]
What is the difference between "IP#" and "IPv#"?
none
What percent of today's packets are IPv4 packets?
95
What is the major drawback of IPv4?
addresses are limited to 32 bits
How many bits can an IPv6 address use?
128
Does a machine have to choose between having an IPv4 and IPv6 address? If so, which one will it choose?
no - it can have both
What are 127.0.0.1 and 0:0:0:0:0:0:1?
addresses of localhost
What is ::1?
shortened version of 0:0:0:0:0:0:1
How many bits can a port number have?
16
What is a port?
globally numbered pipe that processes can access
What is special about ports < 1024?
only root processes can use them
What is the port # for unencrypted HTTP requests?
80
What does TCP guarantee that UDP doesn't? (Hint: 2 separate things)
all packets will arrive, packets will be in order
What percentage of UDP packets are dropped between 2 distant datacenters?
3%
Why is UDP useful even though it isn't 100% reliable?
faster than TCP
Does UDP use connections? Does TCP?
no; yes
What does TCP do?
creates a pipe between two machines and hides the low-level details
What protocol (TCP or UDP) do most internet services use today, and why?
TCP; it abstracts out all the details
What protocol (TCP or UDP) does a web browser use?
TCP
[quiz7-networking2]
What is the purpose of getaddrinfo()?
domain name -> IP address (DNS resolution)
What does getaddrinfo() return? Why?
linked list of addrinfo structs, multiple addresses may be available
What does getnameinfo() do?
gets IP address info from getaddrinfo()
What 2 functions does getnameinfo() replace?
gethostbyaddr(), getservbyport()
What are the advantages of getnameinfo() over the 2 functions it replaces?
reentrant, doesn't care about IP4-vs-6
What is the purpose of DNS?
convert domain names to IP addrs
What protocol does DNS use internally?
UDP
Is DNS secure on its own? Why (not)?
no; requests unencrypted
What 3 calls (in the correct order) connect us to a TCP server?
getaddrinfo(), socket(), connect()
What does socket() return?
a file descriptor
Which function actually attempts a connection to a TCP server?
connect()
What parameters does connect() accept? Why does it need a size parameter?
file descriptor, address struct, address struct size (ASS); ASS can vary
What's the shortcut function to free an addrinfo struct?
freeaddrinfo()
What do we use to print out getaddrinfo errors? (Hint: it isn't errno)
gai_strerror(result)
What are hints?
addrinfo search parameters
What do AF_INET and AF_INET6 do?
switch between IPv4 and IPv6 in getaddrinfo()
What two types of address can getaddrinfo() accept?
domain name, IP address
[quiz7-networking3]
What are the 4 parts to an HTTP request (in order)?
method, resource, protocol, 2 newlines
How many digits does an HTTP response code have?
3
What do "htons" and its ilk do?
convert between processor and internet endianness
What class of machines actually need "htons" et al. (among others)?
x86
What are the "big 4" TCP server creation calls (in order)?
socket(), bind(), listen(), accept()
Which calls used to create a UDP server? (Hint: there are 2, not 4)
socket(), bind()
What does socket() do?
creates a 'network descriptor'
What does bind() do?
links a socket to a hostname/port
What does listen() do? (Hint: it's non-blocking)
set size of listen queue
What waiting room size do high performance servers use?
128+
What happens when a remote client connects to a server?
it's moved to an unused port for future communication
Do server sockets close if the client disconnects?
no
What does accept() do? (Hint: it does block)
wait for new connection requests and assign them to their own FD
What is the gotcha with accept()?
we MUST use the FD it returns, NOT the server's socket FD
When creating a TCP server, what hint MUST we specify in getaddrinfo()?
SOCK_STREAM
What happens if we try to re-use a previously taken (in our program) port (by default)?
crash and burn
How can we safely reuse ports?
use SO_REUSEPORT in setsockopt()
What must we do when not specifying all the parameters of an addrinfo struct?
zero it out
Ports are per-_______.
machine
What happens if a process quits without letting go of its ports? (Hint: kill-hack.sh)
they're still taken
Do we have to specify a port for a TCP client?
no
How do we specify a specific port for a TCP client to use?
bind() before connect()
[quiz7-networkManpages]
What are the 2 variants of strerror_r()? Which one is preferred, if any?
both GNU and XSI variants accept a user-supplied buffer, but only XSI requires it; XSI
What happens if strerror() receives an undefined errno?
returns some non-NULL value
(Reminder) What is the purpose of getaddrinfo()'s hints argument?
change address query criteria
What are the 3 main valid values for hints.ai_family?
AF_INET, AF_INET6, AF_UNSPEC
What are the 3 main valid values for hints.ai_family?
SOCK_STREAM, SOCK_DGRAM, 0 (any type)
What happens if one of hints' non-int values is set before passing into getaddrinfo()?
undefined
What does the AI_PASSIVE flag do?
uses TCP if set, UDP otherwise (CONFIRM)
What happens if getaddrinfo()'s first parameter is null?
returns info for localhost
What does AI_V4MAPPED do?
if specified in hints.ai_flags, getaddrinfo() returns IPv6 mappings for IPv4 addresses
What happens if socket() receives a datatype (eg. SOCK_STREAM) and a protocol that don't logically match up?
it errors
How are incomplete connections handled in listen()'s queue?
system-dependent
What happens if listen() is called with a non-positive size value?
clamps size at system-dependent min value
What happens to the address output if accept() accepts a connection with an unbound client?
becomes garbage
How can we make connect() non-blocking?
set O_NONBLOCK on its FD
What happens to the would-be socket if connect() is interrupted?
its generated async'ly
[quiz7-scheduling]
What is the order of TCP establishment signals?
SYN; SYN-ACK; ACK
What is a SYN flood?
sending many SYN packets and not ACKing them
What is the purpose of a SYN?
synchronize sequence #s
What is the purpose of the sequence number?
allows TCP to correctly order data
What does TCP stand for?
transmission control protocol
What does UDP stand for?
user datagram protocol
Where does TCP store its IP addresses?
in the enclosing packet
What is the idea behind TCP's receiving window?
receiver tells sender how much data they want
How does TCP avoid congestion issues?
by limiting the number of unacknowledged packets
What makes a processor scheduling method "preemptive"?
interrupts existing job if a more optimal one exists
Which processor schedulers have bad I/O parallelism?
first come first serve, non-preemptive shortest job first
What scheduler does Linux use?
stride scheduler that gives more time to processes who haven't used much recently
What is another name for a stride scheduler?
completely fair scheduler
What happens if TCP runs out of sequence numbers?
loops back to 0
What is silly window syndrome?
using a receiving window smaller than the TCP header
What is the idea behind TCP's persist timer?
if a window size update is missed, ask nicely for a new one instead of waiting forever
What does the TCP_NODELAY option tell TCP to do?
don't wait for a full packet's worth of data before sending
Does UDP have any built-in congestion control mechanism?
no
[quiz8-files1]
What are the two overarching goals of a file system?
CIA triad, performance
What does . mean in a path?
current directory
What does .. mean in a path?
parent directory
What does ... mean in a path?
INVALID!
What is an absolute path?
a path starting from the root directory
What is a relative path?
a path not starting from the root directory
In a UNIX path, what does ~ represent?
home directory
Why are disk blocks the same size as memory pages?
so we can page things in and out of memory
What information is stored for each file? (Hint: ACM, SINC-APP)
name, size, accessed/created/modified time, permissions, path, checksum, inode
What are the 3 UNIX file permissions?
read, write, execute (rwx)
Are directories inodes? Are files?
yes to both
How do inodes store file contents?
as pointers to disk blocks
How many pointers fit in each indirection table?
DO THIS EXAMPLE PROBLEM!
[quiz8-files2]
If the file name isn't the actual file, what is?
the inode
What is a directory?
mapping of names to inode #s
Are directories inodes?
yes!
What terminal command lets us find inode #s?
ls -i
What C command lets us find inode #s?
*stat()
List the 3 variants of stat().
fstat(), lstat(), stat()
What does fstat() do?
stat() for fd's
What does lstat() do?
stat() for symbolic links
What information does stat() return?
all information on the inode
What 3 functions can I use to enumerate the contents of a directory?
opendir(), readdir(), closedir()
Why is calling closedir() after an opendir() important?
prevents zombie fd's/memory leaks
What design pattern is nasty in C? (Hint: Djikstra hates it, like everything else)
exception handling
Does C formally support exception handling?
no
What are the two gotchas of recursing with readdir()?
returns . and .. as well as subdirectories/files
Is readdir() thread safe? If not, what do we use instead?
no; readdir_r()
How do we determine if a directory entry (DIRENT) is a directory?
use S_ISDIR() or S_ISREG() on a DIRENT's st_mode
[quiz8-files3]
What UNIX command do we use to hard link files?
ln
What are 'hard links'?
multiple paths pointing to one file
What C command do we use to hard link files?
link
What do rm and unlink do? (Hint: not deletion)
destroy a name-inode link
When is a file deleted from disk?
when no more links or fd's point to it
How can we 'stealth' files from the OS while keeping them usable?
unlink them completely except for an FD
How are hard links useful in backups?