user land questions
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/1.jpg)
EXAM STYLE QUESTIONS ON USER SPACE
USER LAND QUESTIONS
![Page 2: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/2.jpg)
Question 1 Int pthread_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
![Page 3: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/3.jpg)
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
![Page 4: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/4.jpg)
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
![Page 5: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/5.jpg)
Question 4 Open(2) can be used
To create a new file To open existing file To open a device All of the above
![Page 6: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/6.jpg)
Question 5 mmap(2) should never be used
In threaded application In multi process application With socket as file descriptor None of the above
![Page 7: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/7.jpg)
Question 6 + 7 Following are functions pairs. Please specify if they
are blocking (answers – a = both , b = 1st , c = 2nd d = none) (assume default flags)
Select(2), signal/sigaction(2) b
recv(2),scanf(3) a
![Page 8: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/8.jpg)
Question 8+9
which of the following can we wait using select (a = both b=1st c = 2nd d= none)
stream socket and dgram socket a
POSIX Cond and large matrix multiplication d
![Page 9: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/9.jpg)
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)
![Page 10: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/10.jpg)
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
![Page 11: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/11.jpg)
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
![Page 12: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/12.jpg)
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
![Page 13: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/13.jpg)
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
![Page 14: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/14.jpg)
Question 15
We expect to find system call man pages in man 1 man 2 man 3 man 4
![Page 15: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/15.jpg)
Question 16 We expect to find syslog output under linux (in tau
labs) at /messages /var/log/messages /usr/log/messages ~root/log/messages
![Page 16: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/16.jpg)
Question 17 GDB output
Program terminated with signal 11, Segmentation fault.#0 0x0000000000400492 in crash_here () at crash.c:44 *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
![Page 17: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/17.jpg)
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)
![Page 18: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/18.jpg)
Question 19 In GCC
–o is the compile switch –o is the output switch –o is the optimize switch none of the above
![Page 19: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/19.jpg)
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
![Page 20: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/20.jpg)
Question 21 Syslogd
Is a process Only root can write to syslog Only the kernel can write to syslog None of the above
![Page 21: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/21.jpg)
Question 22 pid_t fork(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
![Page 22: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/22.jpg)
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
![Page 23: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/23.jpg)
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
![Page 24: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/24.jpg)
Question 25 Deadlock can occur
Between threads & processes Between sockets & threads Between environment variable & sockets Between terminals & sockets
![Page 25: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/25.jpg)
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
![Page 26: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/26.jpg)
Question 27 // lines from C program
// … if ((src = mmap (0, statbuf.st_size, PROT_READ,
MAP_SHARED, fdin, 0)) == (caddr_t) -1) // error handling removedif ((dst = mmap (0, statbuf.st_size, PROT_READ |
PROT_WRITE, MAP_SHARED, fdout, 0)) == (caddr_t) -1)// error handling removedmemcpy (dst, src, statbuf.st_size); } /* main */
![Page 27: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/27.jpg)
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
![Page 28: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/28.jpg)
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
![Page 29: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/29.jpg)
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
![Page 30: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/30.jpg)
Question 30 Which of the below is not a scheduling criterion
Max CPU utilization Max throughput Min response time None of the above
![Page 31: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/31.jpg)
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
![Page 32: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/32.jpg)
Question 31+32+33
Following are functions pairs. Please specify if they are blocking (answers – a = both , b = 1st , c = 2nd d = none) (assume default flags)
Toupper(3) and Lseek(2)
munmap(2) and Log(3) (linking with –lm)
Getch(3) and getopt(3)
![Page 33: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/33.jpg)
Question 34+35
which of the following can we wait using select (a = both b=1st c = 2nd d= none)
UDS-Stream Mmap file
Standard error (stderr) FILE *
![Page 34: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/34.jpg)
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
![Page 35: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/35.jpg)
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
![Page 36: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/36.jpg)
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
![Page 37: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/37.jpg)
Question 39 Which statement is not true
Threads are simpler to create then processes We can only use Producer-Consumer in Threads
using posix cond Threads share the entire memory. Further more they
also share the process environment (FD etc.) POSIX threads require compiling with –lpthread on
Linux
![Page 38: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/38.jpg)
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
![Page 39: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/39.jpg)
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
![Page 40: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/40.jpg)
Question 41 Socket(2) system call
Is non blocking for UDS Is required for all forms of IPC Requires –lsocket compile flag A+B
![Page 41: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/41.jpg)
Question 42 Which of the following can be close(2)d
Thread mmap(2)ed file Process Cond
![Page 42: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/42.jpg)
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
![Page 43: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/43.jpg)
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
![Page 44: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/44.jpg)
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
![Page 45: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/45.jpg)
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
![Page 46: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/46.jpg)
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.
![Page 47: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/47.jpg)
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.
![Page 48: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/48.jpg)
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.
![Page 49: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/49.jpg)
Question 53 Which of the following signals cannot be caught
SIGKILL SIGFPE SIGSUSP None of the above A+C
![Page 50: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/50.jpg)
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
![Page 51: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/51.jpg)
Question 55 TWO Scenarios
We want to bind(2) TCP and UDP sockets. We want both sockets to be given the same name. (bind(2)ed to the same port number)
We want to bind(2) UDS-S and UDS-D sockets. We want both sockets to be given the same name. (bind(2)ed to the same path)
![Page 52: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/52.jpg)
Question 56 Using factory I can
Call constructors that require arguments that I can’t call otherwise
Create singletons in procedural languages such as C and Assembler
Add constructors to object that use the factory thus adding functionality
Decouple implementation and representation
![Page 53: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/53.jpg)
Question 57 Codec is
Compressor/decompressor such as winzip File format – such as mp3 Encoder/decoder such as XviD CoDEC (Digital equipment cooperation) a follower of
digital products
![Page 54: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/54.jpg)
Question 58 Av_register_all()
Register all the codecs in the OS Register all the codecs in the ffmpeg factory Initialize all the codecs in the OS Initialize all the codecs used in the stream
![Page 55: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/55.jpg)
Question 59 OOP programming in C
Is impossible. Is possible if we use C99 standard that add class as a
reserved word in C Is actually C++ for example – we add class and
constructors but we don’t use STL so it’s still C. Is often done in UNIX. Sometimes conceptually and
sometimes mechanically as the language doesn’t have some mechanics
![Page 56: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/56.jpg)
Question 60 All Factories and the Process signal table both hold
Event handlers Pointers to functions SIGCHLD Ints as keys
![Page 57: USER LAND QUESTIONS](https://reader036.vdocuments.us/reader036/viewer/2022062315/56816203550346895dd227d6/html5/thumbnails/57.jpg)