Tuesday, December 15, 2015

System Programming test answers of 2016.

In this post you can find Complete and recently updated Correct Question and answers of System Programming. All Answers updated regularly with new questions. Upwork System Programming test answers of 2016.



Question:* Where would you expect to encounter the following code? for (i=1; i<argc; i++) { if (argv[i][0] == '-') {

Answer: • In the beginning of the main() function

Question:* Which of the following could the fork() command return to the child process?

Answer: • 0

Question:* Which of the following is true of hard links?

Answer: • Hard links are directory entries that point to the same inode as another file

Question:* An orphan process occurs as a result of which of the following conditions?

Answer: • Parent process terminates before its child process

Question:* Using a terminal you want to log in to an account on a remote computer and securely build. Which would you use?

Answer: • SSH

Question:* You want to listen on a port for some user-defined data stream. Would you use port 80?

Answer: • No, it is a 'well-defined' or reserved port.

Question:* When communicating across sockets, which of the following functions must be used when the socket is in a connected state?

Answer: • send()

Question:* You want the same codebase to conditionally compile on and for different target platforms. Which of the following would you use?

Answer: • #itdef, #ifndef, and #endif

Question:* Using strncpy() to copy strings can help prevent which of the following attacks?

Answer: • Buffer overflow

Question:* 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?

Answer: • fflush()

Question:* Given the following line: my_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0644); Which statement is true?

Answer: • Opens a file descriptor, bitwise OR'ing output flags and in mode 644

Question:* You see the line: listen (s, 3); You are looking at code for:

Answer: • A server's socket

Question:* Race conditions are caused by which of the following conditions in a multithreaded system?

Answer: • Proper program function is dependent on the execution sequence and timing of each thread

Question:* The language of choice for Systems Programming is:

Answer: • None of these

Question:* The purpose of the poll() and select() system calls is to perform which of the following functions?

Answer: • Watch a set of file descriptors to see which are ready

Question:* Which one of the following is NOT applicable in real-time Systems Programming?

Answer: • E-R Schema

Question:* If a function is a 'blocking function' then:

Answer: • The function must terminate before control returns to caller

Question:* Threads and processes are related in which one of the following ways?

Answer: • Each thread exists within a process

Question:* When a new process is created using fork(), which of the following describes the state of open file descriptors?

Answer: • The child inherits the parent’s

Question:* If you see: int ff; write(ff, data, sizeof(data)); you know that ff is:

Answer: • a file descriptor

Question:* What is thread safety?

Answer: • Multiple threads can be executed without corrupting shared data

Question:* Which of the following is correct for the standard file descriptors that are automatically opened in UNIX?

Answer: • STDIN_FILENO = 0, STDOUT_FILENO = 1, STDERR_FILENO = 2

Question:* 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; }

Answer: • No, because both stack depth and stack-frame size are unpredictable

Question:* 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?

Answer: • Standard file access functions

Question:* Which of the following IPC mechanisms has an inode?

Answer: • named pipe

Question:* Which of the following fields in the stat struct contain last time the file was modified?

Answer: • st_mtime

Question:* 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 */ : }

Answer: • line 21: if (my_sock < 0) {

Question:* Any code that calls a function whose interface includes the line raises(aLibrary:BookIsMissing); should do which one?

Answer: • Implement an exception handler

Question:* Which of the following provides the most random seed source for a pseudo random number generator?

Answer: • /dev/random

Question:* Which of the following best describes the purpose of the unlink() call?

Answer: • Removes the file from its directory

Question:* The ioctl() function is used to interact with which of the following?

Answer: • Special character devices

Question:* What does the following line do? memset((char *)&ctl_addr, 0, sizeof(ctl_addr));

Answer: • Initializes the region of memory pointed to by &ctl_addr

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

Answer: • bind(s, &sock_struct, l);

Question:* What does the line #define S_IRWXG 0000070 relate to?

Answer: • Flags for file access

Question:* 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:

Answer: • sched_yield()

Question:* The sticky bit is used to enable which of the following features?

Answer: • Prevent users from renaming or deleting files created by other users

Question:* 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;

Answer: • The present object's ultimate superclass or base class below the root object

Question:* When there are more fork() calls than wait() calls, which of the following is created?

Answer: • zombie

Question:* Thread joining synchronizes threads by doing which of the following?

Answer: • The thread that calls join blocks until all of the joinable threads complete

Question:* You want a char * that will contain the timestamp as YYYYMMDD-hh:mm:ss . You would use:

Answer: • strftime()

Question:* 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?

Answer: • Big endian versus littlen endian

Question:* 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?

Answer: • It isn't possible to tell without looking at my_print_func()

Question:* In an IDL which one of the following is NOT a valid declaration?

Answer: • oneread

Question:* In UNIX, a program requires higher privileges in order to do which of the following?

Answer: • Listen on a port below 1024

Question:* What type of attack can be mitigated by using ulimit, setrlimit(), and quotactrl()?

Answer: • Denial of service

Question:* Which of the following is the result of a process calling UNIX exec()?

Answer: • The process is completely overwritten

Question:* What is a UNIX directory?

Answer: • A file that contains other files

Question:* What is the purpose of a semaphore?

Answer: • To protect a critical section of code

Question:* Which of the following can be called to remove zombie processes?

Answer: • wait4()

Question:* 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

Answer: • It is neither 'code' nor will the compiler 'see' it

Question:* 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:

Answer: • may use either thread-id or port number

Question:* Which of the following advocates the use of memmove() over memcopy() for performing fast data copying from one buffer to another correctly?

Answer: • The buffers may overlap

Question:* In gdb before using 'jump' you would typically do which one of the following:

Answer: • Set a breakpoint

Question:* A 'crashed' software needs to be debugged using its core dump. You would start by doing:

Answer: • attach

Question:* 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?

Answer: • sock_struct passed by reference

Question:* Which of the following techniques can help keep system programs secure?

Answer: • Check all system calls for error conditions

Question:* Wha does the following line do? unsigned transOK : 1;

Answer: • Identifies a bit in a byte to use as a flag

Question:* In a Publish-And-Subscribe implementation, a subscriber must:

Answer: • Know the event name or event identifier for one or more events

Question:* You want to copy binary contents of memory from one location to another. Which one of these h-files will you #include?

Answer: • string.h

Question:* A thread has its own copy of which of th following?

Answer: • Stack

Question:* 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?

Answer: • The second 4KB of the file will be loaded into a 4KB memory location

Question:* The result of calling kill(6003, 0) is which of the following?

Answer: • The existence of process 6003 is checked

Question:* Which of the following functions sends a signal to the executing process?

Answer: • raise()

Question:* 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); }

Answer: • Re-entrantly tokenizes on delimiter " ” to stringify something

Question:* How can two processes communicate despite having firewalls between them?

Answer: • SOCKS

Question:* 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?

Answer: • S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH

Question:* An Internet socket connection essentially is:

Answer: • Two host addresses and two port numbers

Question:* In a Unix toolchain, which one of these pairs does not fit with the others?

Answer: • Executable and compiler

Question:* CORBA's DII allows a client to do which one of the following?

Answer: • Discover new objects and interfaces at runtime

Question:* Which one of the folloing is NOT necessary for a basic CORBA system?

Answer: • CORBAfacilities

Question:* Which one is not a difference between exit() and _exit()?

Answer: • One is for the main process; the other for forked processes

Question:* 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?

Answer: • The behavior of mkdir() is undefined if anything other than permission bits is set

Question:* In order to create a counting mutex, which mode does it need to use?

Answer: • PTHREAD_MUTEX_RECURSIVE

Question:* Which of the following is an advantage of using pipes over shared memory for interprocess communication?

Answer: • No additional work required on multiple CPU systems without cache coherence

Question:* Thrashing caused by loading a large file can be reduced by mapping the file to memory due to which of the following features?

Answer: • Mapped memory uses lazy loading

Question:* In order to prevent signal handler race conditions, a developer must do which of the following?

Answer: • Call sigaction() to block the signal and set the signal mask at the same time

Question:* What does this code do: BOOL sharedLockSuccess = NO; NSLock *aMutex; : sharedLockSuccess = [aMutex lockWhenCondition:1 beforeDate:[NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)3600]]; :

Answer: • A mutex is tried to be locked within a specific time

Question:* Which of the following could the fork() command return to the parent process?

Answer: • 4066

Question:* Yousee the following function call in some code: pthread_setspecific(key, value); What will this allow the coder to do?

Answer: • Access thread-specific data outside the thread

Question:* 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 */ :

Answer: • Replace the declaration with: int file1;

Question:* What does this code do: [aLock lockWhenCondition:(int)self beforeDate:[NSDate dateWithTimeIntervalSinceNow:maxTimeInterval]];

Answer: • Control blocks for some time on a lock on a condition that is unique to an instance

Question:* 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?

Answer: • Compiler-Dynamic Linker incompatibility

Question:* Sharing memory between processes using mmap vs. shm_open has which of the following advantages?

Answer: • The memory buffer is destroyed when the processes end

Question:* 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?

Answer: • The parent must close pipe_fd[0], and the child must close pipe_fd[1]



No comments:

HTML5 Upwork (oDesk) TEST ANSWERS 2022

HTML5 Upwork (oDesk) TEST ANSWERS 2022 Question: Which of the following is the best method to detect HTML5 Canvas support in web br...

Disqus for upwork test answers