USER LAND QUESTIONS
description
Transcript of USER LAND QUESTIONS
EXAM STYLE QUESTIONS ON USER SPACE
USER LAND QUESTIONS
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
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
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
Question 4 Open(2) can be used
To create a new file To open existing file To open a device All of the above
Question 5 mmap(2) should never be used
In threaded application In multi process application With socket as file descriptor None of the above
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
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
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)
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
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
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
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
Question 15
We expect to find system call man pages in man 1 man 2 man 3 man 4
Question 16 We expect to find syslog output under linux (in tau
labs) at /messages /var/log/messages /usr/log/messages ~root/log/messages
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
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)
Question 19 In GCC
–o is the compile switch –o is the output switch –o is the optimize switch none of the above
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
Question 21 Syslogd
Is a process Only root can write to syslog Only the kernel can write to syslog None of the above
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
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
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
Question 25 Deadlock can occur
Between threads & processes Between sockets & threads Between environment variable & sockets Between terminals & sockets
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
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 */
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
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
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
Question 30 Which of the below is not a scheduling criterion
Max CPU utilization Max throughput Min response time None of the above
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
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)
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 *
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
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
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
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
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
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
Question 41 Socket(2) system call
Is non blocking for UDS Is required for all forms of IPC Requires –lsocket compile flag A+B
Question 42 Which of the following can be close(2)d
Thread mmap(2)ed file Process Cond
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
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
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
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
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.
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.
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.
Question 53 Which of the following signals cannot be caught
SIGKILL SIGFPE SIGSUSP None of the above A+C
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
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)
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
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
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
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
Question 60 All Factories and the Process signal table both hold
Event handlers Pointers to functions SIGCHLD Ints as keys