Elance System Programming Test Answers 2015



Where would you expect to encounter the following code? for (i=1; i<argc; i++) { if (argv[i][0] == '-') {
Anywhere at all
In the beginning of the main() function
In the scanning for an internals function
In the iteration of the fscanf() function


Which of the following could the fork() command return to the child process?
-1
19456
2054
0


If a function is a 'blocking function' then:
The function must terminate before control returns to caller
This function has the highest possible priority
This function's purpose is to block unstructured calls
The function is written using block structuring


Any code that calls a function whose interface includes the line raises(aLibrary:BookIsMissing); should do which one?
Implement an exception handler
#include errno.h header file
Pass both parameters by reference
Properly pass parameter for Book


In UNIX, a program requires higher privileges in order to do which of the following?
Create a file in the /tmp directory
Listen on a port below 1024
Open a file in the owner’s directory
exec() a new process


Which of the following is correct for the standard file descriptors that are automatically opened in UNIX?
STDIN_FILENO = 0, STDERR_FILENO = 1, STDOUT_FILENO = 2
STDERR_FILENO = 0, STDOUT_FILENO = 1, STDIN_FILENO = 2
STDOUT_FILENO = 0, STDERR_FILENO = 1, STDERR_FILENO = 2
STDIN_FILENO = 0, STDOUT_FILENO = 1, STDERR_FILENO = 2


Which of the following is true of hard links?
Files are deleted from disk when a hard link is removed
Hard links are directory entries that point to the same inode as another file
Hard links can cross filesystems


When a new process is created using fork(), which of the following describes the state of open file descriptors?
The child inherits the parent’s
The child always has an empty set of closed descriptors
The child overwrites the parent’s
The child has distinct copies of the parent’s


Which of the following methods is used by system programs to access a character device (such as keyboards, audio cards, etc) on a UNIX system?
Pipes
It depends on the device
Standard file access functions


Which of the following fields in the stat struct contain last time the file was modified?
st_atime
st_mtime
st_ctime


What is thread safety?
Threads don’t start until all of the resources they require are available
Threads can only access the data in its process
Multiple threads can be executed without corrupting shared data


Given the following line: my_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0644); Which statement is true?
Runtime error opening the file as the various flags and modes are in conflict
Syntax error; the function takes only one more argument after 'filename'
Syntax error; the second argument should be a single integer type
Opens a file descriptor, bitwise OR'ing output flags and in mode 644


Threads and processes are related in which one of the following ways?
Each process exists within a thread
Threads and processes exist separately
Each thread exists within a process


An orphan process occurs as a result of which of the following conditions?
Parent process terminates before its child process
Child process terminates before its parent process
Parent and child process terminate simultaneously


Which one of the following is NOT applicable in real-time Systems Programming?
Sequence Diagram
E-R Schema
Event Trace
Timing Diagram


You want the same codebase to conditionally compile on and for different target platforms. Which of the following would you use?
Bit flags and bitwise OR'ing
#itdef, #ifndef, and #endif
if, else if, and else blocks
Use host-specific linkers


Race conditions are caused by which of the following conditions in a multithreaded system?
Proper program function requires all threads to run quickly
Proper program function is dependent on the execution sequence and timing of each thread
Proper program function requires that all threads run at the same speed


Using strncpy() to copy strings can help prevent which of the following attacks?
Buffer overflow
Password cracking
Denial of service
Man-in-the-middle


The language of choice for Systems Programming is:
None of these
LISP
PHP
ALGOL


You see the line: listen (s, 3); You are looking at code for:
A server's socket
A client's server
A server's clients
A client's socket


You want to listen on a port for some user-defined data stream. Would you use port 80?
Yes, it is best ot use low numbers for port numbers.
Yes, it is as good as any other port number.
No, it is best to use three or four digit port numbers.
No, it is a 'well-defined' or reserved port.


Some programme that streams data to a hard-disk file in a loop crashed before it closed the FILE pointer. When the output file is inspected side-by-side with the logs, it is clear that the fprintf() function previous to the crash was unsuccessful. Such a situation can be averted using which one of the following?
fscanf()
fflush()
fbuffer()
sscanf()


Using a terminal you want to log in to an account on a remote computer and securely build. Which would you use?
RSH
rlogin
SSH
EncryptoTelnet


When communicating across sockets, which of the following functions must be used when the socket is in a connected state?
send()
sendto()
sendmsg()


The purpose of the poll() and select() system calls is to perform which of the following functions?
Watch a set of file descriptors to see which are ready
Frequently check email and other network services
Sample system process information for use by the top command


If you see: int ff; write(ff, data, sizeof(data)); you know that ff is:
a file descriptor
a file function
a file pointer
a file struct


Is it good programming that the following function call is recursive? void func(unsigned long a) { unsigned long x; struct t_struct[] *p; : p = (struct t_struct *)alloca(a*sizeof(t_struct)); : While (x = f2()) func(x); : return; }
No, because there is more than one 'long integer' type
Yes, because recursion is always preferable to iteration
No, because iteration is always preferable to recursion
No, because both stack depth and stack-frame size are unpredictable


The sticky bit is used to enable which of the following features?
Aggressive caching of a process
Keep a process from swapping out of memory
Prevent users from renaming or deleting files created by other users


Which of the following provides the most random seed source for a pseudo random number generator?
/dev/random
C rand() function


What does the following line do? memset((char *)&ctl_addr, 0, sizeof(ctl_addr));
Given that 0 is passed, it unsets the memory of ctl_addr
Initializes a subset of memory pointed to by &ctl_addr
Initializes the region of memory pointed to by &ctl_addr
Allocates and initializes memory for variable ctl_addr


Correct the following code: 10 int my_sock; : 20 my_sock = socket(anaddr.sin_family, SOCK_STREAM, 0); 21 if (my_sock >= 0) { /* error processing */ : }
line 20: my_sock = socket(SOCK_STREAM, anaddr.sin_family, 0);
line 20: my_sock = (int *)socket(anaddr.sin_family, SOCK_STREAM, 0);
line 10: SOCKET * my_sock;
line 21: if (my_sock < 0) {


Which of the following IPC mechanisms has an inode?
unnamed pipe
shared memory
named pipe
semaphore


The ioctl() function is used to interact with which of the following?
Disk Drives
Virtual TTY lines
Special character devices


Which of the following is an advantage of using pipes over shared memory for interprocess communication?
Pipes connect processes on multiple machines
Pipes can be shared by more processes
No additional work required on multiple CPU systems without cache coherence
Faster access time


Thread joining synchronizes threads by doing which of the following?
The joined threads are added to a queue and executed serially
The thread that calls join blocks until all of the joinable threads complete
The system manages the shared resources for the joined threads


Which of the following best describes the purpose of the unlink() call?
Moves the file in from one directory to another
Sets the file’s inode count to one (1)
Removes the file from its directory


Using two resident processes on a PC and a Unix box, you are streaming unbuffered the contents of a text-file byte by byte from the PC to the Unix box where it is written byte by byte to the local hard disk. Eyeing the written file it is obvious that it is not quite right. You have likely run into which problem?
Text file versus binary file
Ignoring the parity bit
Not using buffered streaming
Big endian versus littlen endian


What does the following function return? Class retVal = [self class]; if ([retVal class] != [NSObject class]) { while ([retVal superclass] != [NSObject class]) retVal = [retVal superclass]; } return retVal;
The present object's superclass or base class
The present object's ultimate superclass or base class below the root object
The root object
The present object's class


The following code is written to be accessed by multiple detached threads. : const char * c; char * d; : /* no lock and no mutex is used in any way here */ my_print_func (c, &d); : Which one of the following will happen when this code is re-entered by multiple threads?
One thread will run while others will crash or abort
It isn't possible to tell without looking at my_print_func()
The code will sometimes run and sometimes cause a crash
The code will always cause a crash


When there are more fork() calls than wait() calls, which of the following is created?
daemon
orphan
zombie
thread


What does the line #define S_IRWXG 0000070 relate to?
Alpha-numeric interchange
Defining bitwise flags
User-defined typing
Flags for file access


You want a char * that will contain the timestamp as YYYYMMDD-hh:mm:ss . You would use:
sprintf()
get_datetime()
localtime()
strftime()


Given: int s, l; struct sockaddr_un sock_struct; Choose the option that corrects the following line: bind(s, sock_struct, l);
bind(s, sizeof(sock_struct), l);
bind(sock_struct, s, l);
bind(s, l, sock_struct);
bind(s, &sock_struct, l);


What type of attack can be mitigated by using ulimit, setrlimit(), and quotactrl()?
Buffer Overflow
Password cracking
Man-in-the-middle
Denial of service


Which of the following can be called to remove zombie processes?
close()
free()
flush()
wait4()


Thrashing caused by loading a large file can be reduced by mapping the file to memory due to which of the following features?
Mapped memory is cached
Mapped memory uses prefetching
Mapped memory uses lazy loading


In Multi-Threaded programming you want an active thread to push itself back in the background in favour of some other thread. You will use which function:
pthread_detach()
pthread_setschedparam()
pthread_cancel()
sched_yield()


What is a UNIX directory?
A special type of inode
A file that contains other files
A list of files


Which of the following is the result of a process calling UNIX exec()?
The process is completely overwritten
A new process is created
The process blocks waiting for another process to run
The process becomes executable


In an IDL which one of the following is NOT a valid declaration?
enum
oneread
readonly
oneway


In order to prevent signal handler race conditions, a developer must do which of the following?
Call sigaction() to block the signal and set the signal mask at the same time
Call sigsetmask() to set the signal mask to be blocked
Create a mutex within the handler to protect shared resources


CORBA's DII allows a client to do which one of the following?
Discover new objects and interfaces at runtime
Connect with proxy objects across platforms
Dynamically link with cross-platform libs
Generate client-side stubs for interfaces


In a Publish-And-Subscribe implementation, a subscriber must:
Know the event name or event identifier for one or more events
Use two-way messaging
(all of these)
Be connected to one or more event publishers


A thread has its own copy of which of th following?
Address space
Files
Stack
Variables


Which is true, given the following code: tok = strtok_r(data, " ”, &last); while (tok) { strcat(strcpy(full_name, the_path), tok); make_secondary(eAma_full_name, TRUE); tok = strtok_r(NULL, " ”, &last); }
Should not pass last by reference inside the while() loop
Re-entrantly tokenizes on delimiter " ” to stringify something
The syntax is wrong; it should be strtok(char *, const char *)
Passing NULL as the first param to strtok_r() is an error


A 'crashed' software needs to be debugged using its core dump. You would start by doing:
backface
step
inspect
attach


What will happen when the compiler 'sees' the following code? #define FTP_TYPE "" #ifdef -FTP #define FTP_TYPE "FTP" #elif #ifdef -PASV #ifndef FTP_TYPE #define FTP_TYPE "PASV" #endif #endif
Compile will proceed with a warning of #define'ing a symbol as a string
It's not a question of 'when' but if: compiler will 'see' it only if -FTP or -PASV is set
Compile will fail with an error of #define'ing a symbol as a string
It is neither 'code' nor will the compiler 'see' it


Which one is not a difference between exit() and _exit()?
One is for the main process; the other for forked processes
One does some work on its own, then calls the other
One flushes and closes I/O streams; the other doesn't
One is a true system call; the other is a library routine


The result of calling kill(6003, 0) is which of the following?
Process 6003 terminates
The signal 0 is sent to process 6003
The existence of process 6003 is checked
The signal 6003 is sent to process 0


Which of the following techniques can help keep system programs secure?
Limit system calls to administrators
Check all system calls for error conditions
Setuid important processes to the root user
Encrypt every process’ executable


What is the purpose of a semaphore?
To protect a shared memory region
To protect shared variables
To protect a critical section of code


Which of the following advocates the use of memmove() over memcopy() for performing fast data copying from one buffer to another correctly?
The buffers will not overlap
The buffers may overlap
The buffers are large
The buffers are small


Wha does the following line do? unsigned transOK : 1;
It sets the transOK flag to 1
Declares an unsigned integer and sets it to 1
Identifies a bit in a byte to use as a flag
Conducts a bitwise operation on transOK and 1


You want to copy binary contents of memory from one location to another. Which one of these h-files will you #include?
stdio.h
locate.h
string.h
mem.h


You are coding a multi-threaded server in which n detached threads will listen on n ports with a permanent one-to-one association between threads and ports during the lifetime of the process. You want to uniquely identify each thread-port pair. To do so you:
can use thread-id but not port number
may use either thread-id or port number
must use both thread-id and port number
can use port number but not thread-id


Yousee the following function call in some code: pthread_setspecific(key, value); What will this allow the coder to do?
Insert key-value pairs into a thread's dictionary
Access thread-specific data outside the thread
Use a key to identify a thread
Enable a thread to set and use data


Sharing memory between processes using mmap vs. shm_open has which of the following advantages?
The memory buffer is destroyed when the processes end
The memory buffer is persistent beyond the life of the processes
The memory buffer automatically expands to meet the needs of the processes
The memory buffer more quickly accessed


Calling mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, input_fd, 4096), where input_fd is the file descriptor of a 16KB file will cause which of the following to occur?
The first 4KB of the file will be loaded into a 4KB memory location
The second 4KB of the file will be loaded into a 4KB memory location
The fourth 4KB of the file will be loaded into a 4KB memory location
The third 4KB of the file will be loaded into a 4KB memory location


In gdb before using 'jump' you would typically do which one of the following:
Do a backtrace
Either 'step' or 'next'
Set a breakpoint
gdb has no 'jump' instruction


Given: int s, l; struct sockaddr_un sock_struct; The following function call: connect(s, &sock_strict, l); fails. Which one is NOT a reason for it to fail?
sock_struct passed by reference
No server bound on sock_struct
Sercer not listening on sock_struct
The value of s is negative


Changing the mode of a file to be -rwxr-xr-x via the chmod system call can be achieved by setting the mode to which of the following values?
S_ISVTX | S_ISUID | S_IRGRP | S_IWGRP | S_IRXOTH
S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
S_IRWXU | S_IWGRP | S_IXOTH | S_IRWXO
S_IRUSR | S_IRWXG | | S_IROTH | S_IXOTH


Which one of the folloing is NOT necessary for a basic CORBA system?
Naming Services
Stub and skeleton
CORBAfacilities
IDL files


How can two processes communicate despite having firewalls between them?
SOCKS
HTTP
HTTPS
(none of these)


Which of the following functions sends a signal to the executing process?
raise()
signal()
call()
send()


An Internet socket connection essentially is:
The ANSI-defined SOCK_ADDR * structure
A combination of file pointers and streams
A specific, system-defined socket structure
Two host addresses and two port numbers


Choose the answer that corrects the following code. FILE * file1; : if ((file1 = open("/valid_dir/existing_file", O_RDONLY, 0666)) == ERROR) { /* /valid_dir/existing_file is guaranteed to exist */ :
Replace the declaration with: int file1;
Use either one of 'O_RDONLY' and '0666'
Bitwise OR O_RDONLY with another flag
Do not open a file within a condition


What does this code do: [aLock lockWhenCondition:(int)self beforeDate:[NSDate dateWithTimeIntervalSinceNow:maxTimeInterval]];
A lock is locked if and when self is instantiated before a specific date-time
A lock is set using a compound condition comprising of self and a time interval
Control blocks for some time on a lock on a condition that is unique to an instance
It will have no effect at all


It is not possible to set the sticky bit of a file when creating it. Therefore it is necessary to create the directory and then set the sticky bit by executing: mkdir(“/tmp/dir”, 0744); chmod(“/tmp/dir”, 07744). Why?
The mkdir() command is privileged, and doesn’t allow any modification to permissions
The behavior of mkdir() is undefined if anything other than permission bits is set
UNIX requires that directories be created before any non-permission bits are set


In a Unix toolchain, which one of these pairs does not fit with the others?
Object file and linker
Header file and preprocessor
Executable and compiler
Quads and assembler


A pipe has been created, and fork() and exec() calls have been completed. What steps must be taken next in order to establish communication from the parent to the child?
The child must create a new pipe
The parent must close pipe_fd[0], and the child must close pipe_fd[1]
The parent must create a new pipe
The parent must close pipe_fd[1], and the child must close pipe_fd[0]


In order to create a counting mutex, which mode does it need to use?
PTHREAD_MUTEX_NORMAL
PTHREAD_MUTEX_ERRORCHECK
PTHREAD_MUTEX_DEFAULT
PTHREAD_MUTEX_RECURSIVE


What does this code do: BOOL sharedLockSuccess = NO; NSLock *aMutex; : sharedLockSuccess = [aMutex lockWhenCondition:1 beforeDate:[NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)3600]]; :
A mutex is tried to be locked within a specific time
A mutex is being set to be locked at a specific time
A mutex is tried to be locked with a specific condition
A mutex is being set to be locked upon a specific condition


Which of the following could the fork() command return to the parent process?
-1
4066
206896
0


Recently your office's UNIX tool-chain was updated. Now, code that previously used to build and run still builds without any warnings or errors but displays load-time errors due to symbols not found in shlibs. You have ensured that all necessary shared libraries are present in the path 'pointed to' by the appropriate environment variable. Which is true?
Shared libraries should have been updated
Debugging info flags missing in Makefile
Outdated symbols in symbol table or link table
Compiler-Dynamic Linker incompatibility