1 / 57

USER LAND QUESTIONS

USER LAND QUESTIONS. EXAM STYLE QUESTIONS ON USER SPACE. Question 1. Int pthread_create(pthread_t *thread, const pthread_attr_t * attr , void *(* start_routine)(void *), void * arg ); The 4 th argument to pthread_create Will include the return value of the thread

deliz
Download Presentation

USER LAND QUESTIONS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. USER LAND QUESTIONS EXAM STYLE QUESTIONS ON USER SPACE

  2. Question 1 • Intpthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); • The 4th argument to pthread_create • Will include the return value of the thread • Will include the heap of the created thread • Will include the heap of the created thread if not NULL • None of the above

  3. Question 2 • Datagram sockets • Are only usable in UNIX domain sockets • Should not be used for internet streaming protocols (such as RTP) • Send packets that are never broken or spliced • Cannot be used on Microsoft Windows

  4. Question 3 • Socket is used to • Create communication end point • Connect to a server • Bind a port • Only by programs that work with the internet

  5. Question 4 • Open(2) can be used • To create a new file • To open existing file • To open a device • All of the above

  6. Question 5 • mmap(2) should never be used • In threaded application • In multi process application • With socket as file descriptor • None of the above

  7. Question 6 + 7 • Following are functions pairs. Please specify if they are blocking (answers – a = both , b = 1st , c = 2ndd = none) (assume default flags) • Select(2), signal/sigaction(2) • b • recv(2),scanf(3) • a

  8. Question 8+9 which of the following can we wait using select (a = both b=1stc = 2ndd= none) • stream socket and dgram socket • a • POSIX Cond and large matrix multiplication • d

  9. Question 10 • TCP server (AF_INET, SOCK_STREAM) calls functions in the following order • Socket(2), connect(2), accept(2),recv(2) • Open(2), bind(2), connect(2), send(2) • Socket(2), bind(2), listen(2), accept(2) • Open(2), bind(2), connect(2), recv(2)

  10. Question 11 • UNIX domain sockets are • Faster the AF_INET socket • Only work on the same host • One of the many forms of IPC (Inter process communication) • All of the above

  11. Question 12 • What is wrong in the following code While (time(NULL) >time_to_start) • The following code will take 100% cpu while waiting (busy waiting) • The time(2) function is deprecated • The time(2) function is not thread safe • There is nothing wrong with that code

  12. Question 13 • When in main we call pthread_create twice and no thread has finished. How many threads are in the process? • 1 • 2 • 3 • 4

  13. Question 14 • Two scenarios Scenario A process open(2) a file. Call fork(), parent calls exit(2).Child still has some work to do. Scenario B process open(2) a file. Call pthread_create(3), first thread finishes it’s work. Calls exit(2), 2nd thread still has work to do. • BOTH scenario’s are OK • ONLY A scenario is OK • ONLY B scenario is OK • BOTH should FAIL

  14. Question 15 • We expect to find system call man pages in • man 1 • man 2 • man 3 • man 4

  15. Question 16 • We expect to find syslog output under linux (in tau labs) at • /messages • /var/log/messages • /usr/log/messages • ~root/log/messages

  16. Question 17 • GDB output Program terminated with signal 11, Segmentation fault. #0 0x0000000000400492 in crash_here () at crash.c:4 4 *c=12; • The programmer accessed a memory she has not allocated • The programmer had an endless loop/damned recursion • The programmer had called a system call/function with bad parameters • The programmer divided by 0

  17. Question 18 • Process 24501 attached - interrupt to quit select(50, [], NULL, NULL, {0, 0}) = 0 (Timeout) select(50, [], NULL, NULL, {0, 0}) = 0 (Timeout) select(50, [], NULL, NULL, {0, 0}) = 0 (Timeout) select(50, [], NULL, NULL, {0, 0}) = 0 (Timeout) select(50, [], NULL, NULL, {0, 0}) = 0 (Timeout) • What’s wrong? • The programmer forgot select ruins it’s arguments • There is nothing wrong with the program • Select(2) FD_SET is broken • Select is deprecated use pselect(2)

  18. Question 19 • In GCC • –o is the compile switch • –o is the output switch • –o is the optimize switch • none of the above

  19. Question 20 • In UNIX • Each process has environment (char ** environ) • Each process has Parent process ID • Each process has current working directory • All the above

  20. Question 21 • Syslogd • Is a process • Only root can write to syslog • Only the kernel can write to syslog • None of the above

  21. Question 22 • pid_tfork(void); • fork(2) • Should never be used with the standard library • If we have buffers that are not flushed they may be duplicated • Should usually not be used if we also use threads unless we call execXX(2) afterwards • B+C

  22. Question 23 • Producer-Consumer • Is a situation where one task consume all the memory and does nothing useful (while the producer actually does something that is required • Is a situation where one task consume some resource (memory/IO/CPU) damaging more important producer tasks • Is a situation where tasks that produce more output also consume more resources • Is a situation where we have two tasks one producing work packet and the other handling (=consume) them

  23. Question 24 • We can use socket messages • To deliver information between process • To make a cond like mechanism between process (only after receiving the messages you can work) • When we want to do I/O multiplexing and use select to read from stdin and another process (all in a single process) • All the above

  24. Question 25 • Deadlock can occur • Between threads & processes • Between sockets & threads • Between environment variable & sockets • Between terminals & sockets

  25. Question 26 • Comparing mmap(2) and read(2)/write(2) Apis Read/write should be used • When we want to maximize performance • When we have read(2)/write(2) permissions • When we want to maximize portability • B+C

  26. Question 27 • // lines from C program // … if ((src = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED, fdin, 0)) == (caddr_t) -1) // error handling removed if ((dst = mmap (0, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fdout, 0)) == (caddr_t) -1) // error handling removed memcpy (dst, src, statbuf.st_size);  } /* main */

  27. Question 27 • The files will not be copied because we didn’t call msync(2) • The files will not be copied because we didn’t call munmap(2) • The files will be copied after we fall from main (assuming the computer was still on) • A+B

  28. IMPORTANT NOTE REGARDING Q 27 • Falling from main does not call munmap • Mmap marks buffer as dirty (as we’ll learn later) • After a while the kernel will put the dirty buffers to disk • If we call munmap we can force write. If we write again we can save writes • But under no circumstances exit checks for memory buffers and calls munmap

  29. Question 28+29 • Virtual memory • Works in Linux • Works in UNIX • Works in Windows • All of the above • Virtual memory • Reside in memory until we call rmmod • Is a different kind of memory • Allows running programs that require more memory then we currently have • Slows the PC down (due to page faults) and therefore is not used in modern OS

  30. Question 30 • Which of the below is not a scheduling criterion • Max CPU utilization • Max throughput • Min response time • None of the above

  31. Question 31 • The simplest way to transfer multiple arguments to thread is • Put args in a file. Transfer filename • Put args in hash table. Transfer key to each thread • Put args in struct. Transfer struct * • There is no simple way

  32. Question 31+32+33 Following are functions pairs. Please specify if they are blocking (answers – a = both , b = 1st , c = 2ndd = none) (assume default flags) • Toupper(3) and Lseek(2) • munmap(2) and Log(3) (linking with –lm) • Getch(3) and getopt(3)

  33. Question 34+35 which of the following can we wait using select (a = both b=1stc = 2ndd= none) • UDS-Stream Mmap file • Standard error (stderr) FILE *

  34. Question 36 • Virtual memory algorithms (LRU, 2nd fault etc.) • Minimize page faults • Minimize their own processing time • Minimize process wait time on ready queue • Minimize virtual memory usage

  35. Question 37 – which of the two scenarios is legal • Scenario A – process calloc(3) memory on the heap. Calls fork(2) father and child process use fcntl(2) for locking and communicate via the calloced memory as shared memory • Scenario B – process callc memory on the heap. Calls pthread_create(3) both threads use fcntl(2) for locking and communicate via the calloced memory as shared memory

  36. Question 38 • In UNIX zombie is • A type of daemon that does no I/O • The saved returned value of a child process that was not yet wait(2)ed for by father • A process that is doing busy waiting for a long time • MS windows

  37. Question 39 • Which statement is not true • Threads are simpler to create then processes • We can only use Producer-Consumer in Threads using posixcond • Threads share the entire memory. Further more they also share the process environment (FD etc.) • POSIX threads require compiling with –lpthread on Linux

  38. Question 40 • In UDS-Stream • We implement all TCP algorithms (window size and checksum) and gain performance because we limit them to local host • We can send information to remote host if we use NFS mounted files as path • We can use mmap(2) to speed up receiving time • None of the above

  39. Question 40 - GRID • GRID book-keeping • Is used to decide how much to charge user for resource consumption • Is one of the methods used for GRID user management • Is only done for I/O of over 150MB • Is done by each computer to monitor how much of it's resources the GRID consumes

  40. Question 41 • Socket(2) system call • Is non blocking for UDS • Is required for all forms of IPC • Requires –lsocket compile flag • A+B

  41. Question 42 • Which of the following can be close(2)d • Thread • mmap(2)ed file • Process • Cond

  42. Question 43 • When we implement Daemons • We setsid() to change our running user to root so that we run with admin privileges • We close stdin to avoid memory thrashing after loosing controlling terminal • We chdir(“/”) so that we can use syslog in /var/log/messages instead of <cwd>/var/log/messages • We fork(2) twice or more to decrease our priority compared to user tasks • None of the above

  43. Question 44+45+46 • Regarding each pair write true or false • Virtual memory managed by MMU • Include real memory • Includes shared libraries • Includes disk files • Includes memory mapped files • Includes remote memory on GRID environment • Includes swapped pages

  44. Question 47 • Signal handler function • Gets an int for argument the pid of the process receiving the signal • Gets an int for argument the severity of the signal • Gets an int for argument the signal called • Gets an int for argument – enum for the suggested action

  45. Question 48 • SDL • Is a cross platform library used to decode videos • Can be used on Macintosh to simulate a VM • Can be used on Linux to display video and audio • Only works with Bruce Springsteen songs • A+C

  46. Question 49 • Two scenarios • Scenario A – Process accept(2) TCP connection. Calls fork(2). Two things happen simultaneously. Child handles connection. Parent close(2) the socket. • Scenario B – Process accept(2) TCP connection Calls Pthread_create(3). Two things happen simultaneously. New thread handles the connection. Main thread close(2) the connection.

  47. Question 50 • Two scenarios • Two process work in producer consumer environment. They have a connection using UDS. When producer is done producing he sends a byte to consumer. Consumer is waiting on select(2)-when FD_ISSET Consumer will recv(2) 1 byte. • Two Threads work in producer consumer environment. They have a connection using UDS. When producer is done producing he sends a byte to consumer. Consumer is waiting on select(2)-when FD_ISSET Consumer will recv(2) 1 byte.

  48. Question 51+52 • 51 - TWO scenarios • Process forks(3) both parent and child calls strtok(3) • We call pthread_create both threads call strtok_r(3) • 52 – TWO scenarios (what is LEGAL!) • We don’t use threads. We compile with –lpthread • We use threads. We compile with –lpthread.

  49. Question 53 • Which of the following signals cannot be caught • SIGKILL • SIGFPE • SIGSUSP • None of the above • A+C

  50. Question 54 • TWO scenarios • Process A wants to communicate with process B using UDS-Stream. Process A and Process B runs on different hosts. We need max throughput. • Thread A wants to communicate with thread B using UDP . Thread A and Thread B runs on different hosts. We cannot afford to lose data

More Related