System Programming MCQs

System Programming MCQs

Our team has conducted extensive research to compile a set of System Programming MCQs. We encourage you to test your System Programming knowledge by answering these multiple-choice questions provided below.
Simply scroll down to begin!

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

A.   In the scanning for an internals function

B.   Anywhere at all

C.   In the iteration of the fscanf() function

D.   In the beginning of the main() function

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

A.   Initializes a subset of memory pointed to by &ctl_addr

B.   Given that 0 is passed, it unsets the memory of ctl_addr

C.   Initializes the region of memory pointed to by &ctl_addr

D.   Allocates and initializes memory for variable ctl_addr

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

A.   Timing Diagram

B.   Sequence Diagram

C.   Event Trace

D.   E-R Schema

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

A.   send()

B.   sendto()

C.   sendmsg()

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

A.   SSH

B.   RSH

C.   EncryptoTelnet

D.   rlogin

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

A.   A client's server

B.   A client's socket

C.   A server's clients

D.   A server's socket

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

A.   Proper program function requires all threads to run quickly

B.   Proper program function requires that all threads run at the same speed

C.   Proper program function is dependent on the execution sequence and timing of each thread

8: 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?

A.   fflush()

B.   fscanf()

C.   fbuffer()

D.   sscanf()

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

A.   No, it is a 'well-defined' or reserved port.

B.   Yes, it is as good as any other port number.

C.   Yes, it is best ot use low numbers for port numbers.

D.   No, it is best to use three or four digit port numbers.

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

A.   Man-in-the-middle

B.   Buffer overflow

C.   Password cracking

D.   Denial of service

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

A.   Child process terminates before its parent process

B.   Parent process terminates before its child process

C.   Parent and child process terminate simultaneously

12: The language of choice for Systems Programming is:

A.   PHP

B.   ALGOL

C.   LISP

D.   None of these

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

A.   #itdef, #ifndef, and #endif

B.   Bit flags and bitwise OR'ing

C.   Use host-specific linkers

D.   if, else if, and else blocks

A.   Threads and processes exist separately

B.   Each thread exists within a process

C.   Each process exists within a thread

15: If a function is a 'blocking function' then:

A.   The function is written using block structuring

B.   The function must terminate before control returns to caller

C.   This function's purpose is to block unstructured calls

D.   This function has the highest possible priority

A.   Hard links can cross filesystems

B.   Files are deleted from disk when a hard link is removed

C.   Hard links are directory entries that point to the same inode as another file

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

A.   Syntax error; the second argument should be a single integer type

B.   Syntax error; the function takes only one more argument after 'filename'

C.   Runtime error opening the file as the various flags and modes are in conflict

D.   Opens a file descriptor, bitwise OR'ing output flags and in mode 644

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

A.   Frequently check email and other network services

B.   Sample system process information for use by the top command

C.   Watch a set of file descriptors to see which are ready

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

A.   a file descriptor

B.   a file struct

C.   a file function

D.   a file pointer

20: 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; }

A.   Yes, because recursion is always preferable to iteration

B.   No, because iteration is always preferable to recursion

C.   No, because both stack depth and stack-frame size are unpredictable

D.   No, because there is more than one 'long integer' type

21: What is thread safety?

A.   Multiple threads can be executed without corrupting shared data

B.   Threads don’t start until all of the resources they require are available

C.   Threads can only access the data in its process

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

A.   st_ctime

B.   st_mtime

C.   st_atime

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

A.   Aggressive caching of a process

B.   Prevent users from renaming or deleting files created by other users

C.   Keep a process from swapping out of memory

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

A.   STDIN_FILENO = 0, STDOUT_FILENO = 1, STDERR_FILENO = 2

B.   STDOUT_FILENO = 0, STDERR_FILENO = 1, STDERR_FILENO = 2

C.   STDERR_FILENO = 0, STDOUT_FILENO = 1, STDIN_FILENO = 2

D.   STDIN_FILENO = 0, STDERR_FILENO = 1, STDOUT_FILENO = 2

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

A.   The child inherits the parent’s

B.   The child always has an empty set of closed descriptors

C.   The child has distinct copies of the parent’s

D.   The child overwrites the parent’s

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

A.   C rand() function

B.   /dev/random

27: 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?

A.   Standard file access functions

B.   Pipes

C.   It depends on the device

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

A.   #include errno.h header file

B.   Properly pass parameter for Book

C.   Pass both parameters by reference

D.   Implement an exception handler

29: Which of the following IPC mechanisms has an inode?

A.   semaphore

B.   named pipe

C.   shared memory

D.   unnamed pipe

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

A.   line 21: if (my_sock < 0) {

B.   line 20: my_sock = (int *)socket(anaddr.sin_family, SOCK_STREAM, 0);

C.   line 20: my_sock = socket(SOCK_STREAM, anaddr.sin_family, 0);

D.   line 10: SOCKET * my_sock;

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

A.   Mapped memory is cached

B.   Mapped memory uses prefetching

C.   Mapped memory uses lazy loading

A.   Removes the file from its directory

B.   Sets the file’s inode count to one (1)

C.   Moves the file in from one directory to another

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

A.   Disk Drives

B.   Special character devices

C.   Virtual TTY lines

34: 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?

A.   Big endian versus littlen endian

B.   Text file versus binary file

C.   Ignoring the parity bit

D.   Not using buffered streaming

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

A.   bind(s, &sock_struct, l);

B.   bind(s, l, sock_struct);

C.   bind(s, sizeof(sock_struct), l);

D.   bind(sock_struct, s, l);

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

A.   0

B.   -1

C.   2054

D.   19456

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

A.   Listen on a port below 1024

B.   Create a file in the /tmp directory

C.   Open a file in the owner’s directory

D.   exec() a new process

38: 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;

A.   The present object's ultimate superclass or base class below the root object

B.   The present object's superclass or base class

C.   The present object's class

D.   The root object

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

A.   The thread that calls join blocks until all of the joinable threads complete

B.   The system manages the shared resources for the joined threads

C.   The joined threads are added to a queue and executed serially

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

A.   wait4()

B.   free()

C.   close()

D.   flush()

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

A.   thread

B.   daemon

C.   orphan

D.   zombie

42: 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?

A.   The code will sometimes run and sometimes cause a crash

B.   The code will always cause a crash

C.   It isn't possible to tell without looking at my_print_func()

D.   One thread will run while others will crash or abort

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

A.   Pipes can be shared by more processes

B.   Pipes connect processes on multiple machines

C.   No additional work required on multiple CPU systems without cache coherence

D.   Faster access time

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

A.   sprintf()

B.   strftime()

C.   localtime()

D.   get_datetime()

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

A.   Defining bitwise flags

B.   User-defined typing

C.   Flags for file access

D.   Alpha-numeric interchange

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

A.   Man-in-the-middle

B.   Password cracking

C.   Denial of service

D.   Buffer Overflow

47: 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:

A.   sched_yield()

B.   pthread_detach()

C.   pthread_cancel()

D.   pthread_setschedparam()

48: What is a UNIX directory?

A.   A list of files

B.   A special type of inode

C.   A file that contains other files

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

A.   Call sigsetmask() to set the signal mask to be blocked

B.   Create a mutex within the handler to protect shared resources

C.   Call sigaction() to block the signal and set the signal mask at the same time

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

A.   One is a true system call; the other is a library routine

B.   One does some work on its own, then calls the other

C.   One is for the main process; the other for forked processes

D.   One flushes and closes I/O streams; the other doesn't

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

A.   Files

B.   Variables

C.   Address space

D.   Stack

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

A.   string.h

B.   locate.h

C.   mem.h

D.   stdio.h

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

A.   enum

B.   readonly

C.   oneway

D.   oneread

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

A.   A new process is created

B.   The process blocks waiting for another process to run

C.   The process is completely overwritten

D.   The process becomes executable

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

A.   The memory buffer is destroyed when the processes end

B.   The memory buffer automatically expands to meet the needs of the processes

C.   The memory buffer more quickly accessed

D.   The memory buffer is persistent beyond the life of the processes

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

A.   Generate client-side stubs for interfaces

B.   Dynamically link with cross-platform libs

C.   Connect with proxy objects across platforms

D.   Discover new objects and interfaces at runtime

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

A.   The buffers are small

B.   The buffers are large

C.   The buffers may overlap

D.   The buffers will not overlap

58: 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

A.   It's not a question of 'when' but if: compiler will 'see' it only if -FTP or -PASV is set

B.   Compile will proceed with a warning of #define'ing a symbol as a string

C.   Compile will fail with an error of #define'ing a symbol as a string

D.   It is neither 'code' nor will the compiler 'see' it

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

A.   Should not pass last by reference inside the while() loop

B.   The syntax is wrong; it should be strtok(char *, const char *)

C.   Passing NULL as the first param to strtok_r() is an error

D.   Re-entrantly tokenizes on delimiter " ” to stringify something

60: What is the purpose of a semaphore?

A.   To protect shared variables

B.   To protect a critical section of code

C.   To protect a shared memory region

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

A.   inspect

B.   attach

C.   step

D.   backface

62: 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?

A.   The value of s is negative

B.   sock_struct passed by reference

C.   No server bound on sock_struct

D.   Sercer not listening on sock_struct

63: In a Publish-And-Subscribe implementation, a subscriber must:

A.   Be connected to one or more event publishers

B.   Use two-way messaging

C.   Know the event name or event identifier for one or more events

D.   (all of these)

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

A.   Either 'step' or 'next'

B.   Do a backtrace

C.   Set a breakpoint

D.   gdb has no 'jump' instruction

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

A.   Encrypt every process’ executable

B.   Limit system calls to administrators

C.   Setuid important processes to the root user

D.   Check all system calls for error conditions

66: 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?

A.   The third 4KB of the file will be loaded into a 4KB memory location

B.   The fourth 4KB of the file will be loaded into a 4KB memory location

C.   The second 4KB of the file will be loaded into a 4KB memory location

D.   The first 4KB of the file will be loaded into a 4KB memory location

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

A.   Declares an unsigned integer and sets it to 1

B.   Conducts a bitwise operation on transOK and 1

C.   Identifies a bit in a byte to use as a flag

D.   It sets the transOK flag to 1

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

A.   Process 6003 terminates

B.   The existence of process 6003 is checked

C.   The signal 0 is sent to process 6003

D.   The signal 6003 is sent to process 0

69: An Internet socket connection essentially is:

A.   The ANSI-defined SOCK_ADDR * structure

B.   A combination of file pointers and streams

C.   Two host addresses and two port numbers

D.   A specific, system-defined socket structure

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

A.   HTTP

B.   HTTPS

C.   (none of these)

D.   SOCKS

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

A.   signal()

B.   send()

C.   call()

D.   raise()

72: 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:

A.   may use either thread-id or port number

B.   must use both thread-id and port number

C.   can use thread-id but not port number

D.   can use port number but not thread-id

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

A.   Access thread-specific data outside the thread

B.   Enable a thread to set and use data

C.   Insert key-value pairs into a thread's dictionary

D.   Use a key to identify a thread

74: 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?

A.   S_ISVTX | S_ISUID | S_IRGRP | S_IWGRP | S_IRXOTH

B.   S_IRUSR | S_IRWXG | | S_IROTH | S_IXOTH

C.   S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH

D.   S_IRWXU | S_IWGRP | S_IXOTH | S_IRWXO

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

A.   PTHREAD_MUTEX_NORMAL

B.   PTHREAD_MUTEX_RECURSIVE

C.   PTHREAD_MUTEX_ERRORCHECK

D.   PTHREAD_MUTEX_DEFAULT

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

A.   Naming Services

B.   Stub and skeleton

C.   CORBAfacilities

D.   IDL files

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

A.   Bitwise OR O_RDONLY with another flag

B.   Do not open a file within a condition

C.   Use either one of 'O_RDONLY' and '0666'

D.   Replace the declaration with: int file1;

78: 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?

A.   The parent must create a new pipe

B.   The parent must close pipe_fd[0], and the child must close pipe_fd[1]

C.   The child must create a new pipe

D.   The parent must close pipe_fd[1], and the child must close pipe_fd[0]

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

A.   -1

B.   0

C.   206896

D.   4066

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

A.   It will have no effect at all

B.   A lock is set using a compound condition comprising of self and a time interval

C.   A lock is locked if and when self is instantiated before a specific date-time

D.   Control blocks for some time on a lock on a condition that is unique to an instance

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

A.   Executable and compiler

B.   Object file and linker

C.   Quads and assembler

D.   Header file and preprocessor

82: 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?

A.   The mkdir() command is privileged, and doesn’t allow any modification to permissions

B.   The behavior of mkdir() is undefined if anything other than permission bits is set

C.   UNIX requires that directories be created before any non-permission bits are set

83: 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?

A.   Compiler-Dynamic Linker incompatibility

B.   Shared libraries should have been updated

C.   Outdated symbols in symbol table or link table

D.   Debugging info flags missing in Makefile

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

A.   A mutex is being set to be locked upon a specific condition

B.   A mutex is tried to be locked within a specific time

C.   A mutex is being set to be locked at a specific time

D.   A mutex is tried to be locked with a specific condition

85:

Which of the following system calls can be used to send a message via a connected socket?

A.   send

B.   sendto

C.   sendmsg

D.   write

86:

Which of the following are true of Unix system calls?

A.   System calls are executed in "User" context.

B.   The routine "malloc" which is used for allocating memory is a system call.

C.   A new file can be created using the "open" system call.

D.   If two processes are executing the "write" system call simultaneously, they are serialized by the operating system.

E.   The "read" system call will never be blocked.

87:

Which of the following gdb commands can be used to obtain the stack trace of all the threads of a multi threaded program running on Linux?

A.   bt

B.   ::stack

C.   $C

D.   thread apply all bt

88: Which of the following methods can be used as a communication mechanism between two unrelated processes?

A.   A pipe using the pipe system call.

B.   A named pipe using the mknod system call.

C.   Named sockets.

D.   Signals

89: Which of the following Linux commands can be used to identify the processes consuming maximum resources (CPU, Memory)?

A.   ps

B.   top

C.   lsof

D.   vmstat

E.   A.B

90: Which of the following signals are used by the Unix shell to implement job control?

A.   SIGHUP

B.   SIGSTOP

C.   SIGCONT

D.   SIGINT

E.   B.C

91: Which of the following environment variables specifies the shared library search path?

A.   SHARED_LIBRARIES

B.   SHLIB_PATH

C.   LD_LIBRARY_PATH

D.   LIBRARIES

E.   B.C

92: Which of the following utilities would you use on a standard Linux system to debug a running application?

A.   gdb

B.   ltrace

C.   strace

D.   ptrace

93: Which of the following can be used to inspect the system call arguments of a Linux process?

A.   strace

B.   gdb

C.   adb

D.   mdb

94: Which of the following methods can be used to allocate and use memory on a Unix system?

A.   brk

B.   sbrk

C.   malloc

D.   calloc

95: Which of the following utilities is used to generate a core file of a process on Linux?

A.   gdb

B.   strace

C.   gcore

D.   objdump

96: Which of the following can be used to debug the process "123" and program "test" on a Linux system?

A.   adb test 123

B.   gdb test 123

C.   strace 123

D.   strace -f -p 123

97: If a process has locked a System V Semaphore and receives a SIGKILL signal, which of the following is true?

A.   The process can catch the signal and drop the semaphore before terminating.

B.   The process terminates without releasing the semaphore.

C.   The semaphore is released if the process had specified SEM_UNDO during creation.

D.   The signal is deferred until the semaphore is released.

98: Which of the following utilities is used to search out regular expressions in the input?

A.   cat

B.   grep

C.   head

D.   tail

99: What does the command "mknod temp p" do?

A.   It creates a named pipe.

B.   It creates directory nodes

C.   It creates pipes

100:

Threads created via pthread_create need to first set up shared memory using shmop before they can share data.


A.  

True

B.  

False