SYSTEM PROGRAMMING TEST 2016
1. Which of the following system calls can be used to send a message via a connected socket?
Answers:
- send
- sendto
- sendmsg
- write
2. Which of the following methods can be used as a communication mechanism between two unrelated processes?
Answers:
- A pipe using the pipe system call.
- A named pipe using the mknod system call.
- Named sockets.
- Signals.
3. Which of the following are true of Unix system calls?
Answers:
- System calls are executed in “User” context.
- The routine “malloc” which is used for allocating memory is a system call.
- A new file can be created using the “open” system call.
- If two processes are executing the “write” system call simultaneously, they are serialized by the operating system.
- The “read” system call will never be blocked.
4. Which of the following Linux commands can be used to identify the processes consuming maximum resources (CPU, Memory)?
Answers:
- ps
- top
- lsof
- vmstat
5. Which of the following signals are used by the Unix shell to implement job control?
Answers:
- SIGHUP
- SIGSTOP
- SIGCONT
- SIGINT
6. Which of the following environment variables specifies the shared library search path?
Answers:
- SHARED_LIBRARIES
- SHLIB_PATH
- LD_LIBRARY_PATH
- LIBRARIES
7. Which of the following statements are true?
Answers:
- “wc -l” can be used to count the number of lines in the input.
- “find . -name ‘*.txt’ -exec rm {} ;” removes all “.txt” files in the current directory hierarchy.
- “cc -x ” can be used to generate the assembler listing of the C program file.
- “set -x” can be used within a ksh shell script to generate listing of shell commands while they are being executed.
8. Which of the following utilities would you use on a standard Linux system to debug a running application?
Answers:
- gdb.
- ltrace.
- strace.
- ptrace.
9. Which of the following can be used to inspect the system call arguments of a Linux process?
Answers:
- strace
- gdb
- adb
- mdb
10. Which of the following methods can be used to allocate and use memory on a Unix system?
Answers:
- brk
- sbrk
- malloc
- calloc
11. Which of the following utilities is used to generate a core file of a process on Linux?
Answers:
- gdb
- strace
- gcore
- objdump
12. Which of the following can be used to debug the process “123” and program “test” on a Linux system?
Answers:
- adb test 123
- gdb test 123
- strace 123
- strace -f -p 123
13. If a process has locked a System V Semaphore and receives a SIGKILL signal, which of the following is true?
Answers:
- The process can catch the signal and drop the semaphore before terminating.
- The process terminates without releasing the semaphore.
- The semaphore is released if the process had specified SEM_UNDO during creation.
- The signal is deferred until the semaphore is released.
14. 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?
Answers:
- bt
- ::stack
- $C
- thread apply all bt
15. Which of the following shell commands is useful in single stepping through a shell script?
Answers:
- set -x
- echo
- trap
- DEBUG
16. Which of the following utilities is used to search out regular expressions in the input?
Answers:
- cat
- grep
- head
- tail
17. What does the command “mknod temp p” do?
Answers:
- It creates a named pipe.
- It creates directory nodes “temp” and “p”.
- It creates pipes “temp” and “p”
18. Threads created via pthread_create need to first set up shared memory
using shmop before they can share data.
using shmop before they can share data.
Answers:
- True
- False
19. What does the “open” system call return to the caller?
Answers:
- 0 on success and -1 on error.
- File descriptor.
- An integer greater than or equal to 0 on success and -1 on error.
- Always 0.
20. What is the effect of a process executing an unlink system call while another process has opened the same file?
Answers:
- The unlink system call will fail.
- The unlink system call will succeed and the other process will be terminated.
- The unlink system call will be blocked until the other process has closed all references to the file.
- The unlink system call will succeed.
21. Which of the following signals cannot be ignored by a process?
Answers:
- SIGHUP
- SIGINT
- SIGTERM
- SIGKILL
22. Ignoring the setup cost for each of the System V IPC mechanisms, which of the following is the most efficient?
Answers:
- System V, Messages.
- System V, Shared Memory
- System V, Semaphores
- Sockets
23. What command is used to list the shared libraries used by an executable?
Answers:
- ldconfig
- ld
- ldd
- ls
24. What does the following command do to the process with pid 12345?
“kill -9 12345”.
“kill -9 12345”.
Answers:
- It sends the INT signal causing the process to be interrupted.
- It sends the STOP signal causing the process to be stopped.
- It sends the KILL signal causing the process to be killed.
- It sends the HUP singal causing the process to hangup.
25. Which of the following system calls is the most memory efficient method of reading a file?
Answers:
- readv
- read
- mmap
- fcntl
26. Which of the following commands generates a listing of the system calls being executed by a program on Solaris?
Answers:
- ltrace
- tusc
- strace
- truss
27. What is the effect of issuing a “$c” command at the adb prompt during a debugging session on a Solaris 9 system?
Answers:
- It generates a listing of the stack trace.
- It causes the debugger to continue.
- It drops to the shell.
- It prints the register contents.
28. Which of the following sequences prints all the second column fields of an input file “values.txt”?
Answers:
- awk “print $2” values.txt
- awk ‘{print $2}’ values.txt
- awk ‘{print #2}’ values.txt
- cut -2 values.txt
29. Which of the following system calls increases the process priority?
Answers:
- priority
- nice
- ulimit
- fcntl
30. Which of the following is true of Unix system calls?
Answers:
- System calls cannot be executed by regular users.
- System calls are executed in the user context.
- System calls are executed in the kernel context.
- System calls cause a process switch.
31. If a process is hung in the kernel context, sending it a SIGKILL will _____.
Answers:
- kill the process immediately.
- be ignored by the Operating System.
- be delivered when the process switches back to the user context.
32. The library routine printf does not use any system calls.
Answers:
- True.
- False.
33. Which of the following gcc compiler options turns on optimization?
Answers:
- optimize
- O
- Opt
- -S
34. Which of the following options of the compiler is turned on to generate additional debug information (like the source code) for debugging an application?
Answers:
- O
- S
- E
- g
35. Which of the following options specifies a non standard library path during linking?
Answers:
- -l
- -L
- -o
- -g
36. Which of the following shell operators redirects the standard input of the command being executed?
Answers:
- <
- >
- %
- @
37. Which library routine is used to translate the numeric system call error code to a human readable text error message?
Answers:
- sprintf
- exit
- error
- perror
38. Which of the following IPC message operations is performed to setup communication between arbitrary processes?
Answers:
- msgctl
- msgsnd
- msgrcv
- msgget
39. What is the effect of executing the following system call on the file “test.txt”?
open(“test.txt”, O_TRUNC)
open(“test.txt”, O_TRUNC)
Answers:
- The file is truncated to the nearest block size before returning.
- The file is created before returning.
- The file is opened.
- If test.txt exists, the file is truncated to 0 bytes before returning.
40. How does a programmer distinguish a child from its parent process following a fork system call?
Answers:
- The system call returns 0 to the child and 1 to the parent.
- The system call returns 0 to the parent and the pid of the parent to the child.
- The system call returns 0 to the child and the pid of the child to the parent.
- There is no way to distinguish a child from its parent.
41. Which of the following libraries provides the POSIX thread implementation on Solaris?
Answers:
- libpthread
- libthread
- libnptl
- libc
42. Which of the following IPC shared memory sequences is correct?
Answers:
- shmctl, shmat, shmdt
- shmget, shmat, shmdt
- shmctl, shmget, shmat, shmdt
- shmat, shmdt
43. How is the value of the shell environment variable IFS changed to comma (‘,’)?
Answers:
- IFS=’,’; export IFS
- $IFS=’,’; export IFS
- IFS=’,’; export $IFS
- $IFS=’,’
44. Which of the compiler options generates an assembler output file?
Answers:
- -O
- -a
- -S
- -g
45. What does the ‘-pg’ option of the Unix compiler do?
Answers:
- It turns on the profiling of the executable code.
- It generates an assembler listing of the code.
- It turns on the generation of the optimized code.
- It prints the different function call graphs.
46. Shared libraries increase an application’s disk size?
Answers:
- True.
- False.
47. Which of the following redirects the standard error output of a command to the log file “error.log”?
Answers:
- “2>error.log”
- “2
- “>error.log”
- “|error.log”
48. What are the typical system calls the Unix shell invokes when it
has to execute a new command?
has to execute a new command?
Answers:
- open, read, close.
- open, fork, exec.
- ioctl.
49. Which system call is used to send a signal to another process?
Answers:
- signal
- kill
- socket
- ioctl
50. Which of the following commands can be used to generate a listing of all the shared libraries that an executable needs?
Answers:
- ld
- ldd
- ls
- ln
51. What is the default file descriptor used for the error outputs of a process?
Answers:
- 0
- 1
- 2
- -1
52. Which of the following commands can be used on a Linux system to kill process 8977 and all its children?
Answers:
- kill -term 8977
- kill -kill 8977
- kill -stop 8977
- kill -int 8977
53. Which of the following commands can be used on a Linux system to configure a network interface (card)?
Answers:
- ifconfig
- ipconfig
- netstat -c
- route
54. Which of the following commands can be used to list all the active TCP connections only on a Linux system?
Answers:
- netstat -r
- netstat -t
- iptables -L
- route
55. Which of the following ksh trap sequences causes the function ‘handler’ to be executed when the script exits?
Answers:
- trap handler EXIT
- trap EXIT handler
- set handler EXIT
- trap handler exit
56. How many bytes of a file of size 1023 will be read by the following piece of code?
char buf[256];
<snip>
while (read(fd, buf, 256)) {
/* Take some action */
}
<snip>
while (read(fd, buf, 256)) {
/* Take some action */
}
<snip>
Answers:
- 1024
- 1023
- 0
- 768
57. What is the effect of setting the “sticky” bit on an application’s executable image?
Answers:
- It causes the system to load the program faster the next time it runs.
- It causes the system to fail all unlink system call requests on the image.
- It causes the system to preload the application’s image into the system RAM.
- It causes the system to grant the application owner’s privileges to other users if they try to run the application.
58. A C program “domath.c” utilizes the math library. Which of
the following commands correctly creates the corresponding executable
“domath”?
the following commands correctly creates the corresponding executable
“domath”?
Answers:
- cc -o domath domath.c
- cc -o domath domath.c -L /usr/lib -lmath
- cc -o domath domath.c -lm
- cc -o domath domath.c -Lmath
59. Which of the following sequences creates a socket based connection for communication?
Answers:
- open, listen, accept
- open, accept, listen
- socket, connect, accept, listen
- socket, connect, listen, accept
60. What does the open system call return upon success?
Answers:
- A non zero value, which is the file descriptor.
- Zero.
- A positive integer which is the file descriptor.
- The pointer to the FILE structure of the open file.
61. If a process executes the following C code on a Linux system, what is the outcome?
<snip>
char *cp = 0, c = *cp;
<snip>
char *cp = 0, c = *cp;
<snip>
Answers:
- The process executes the code without errors.
- The process is killed with a SIGSEGV.
- The process is killed with a SIGBUS.
- The process is killed with a SIGKILL.
62. On Linux, the pthread_create interface does not use the fork system call to create threads.
Answers:
- True.
- False.
63. Which of the following shell parameters contains the return value of the previously executed shell command?
Answers:
- $*
- $$
- $?
- $!
64. Which of the following calls is used to initiate a socket connection to a target address?
Answers:
- socket
- connect
- accept
- listen
65. Which of the following gcc options can be used to generate a position independent code on a Linux system?
Answers:
- -pic
- +z
- -b
- -mshared
66. Which of the following commands can be used to list all the active TCP connections on a Linux system?
Answers:
- netstat -r
- netstat -t
- iptables -L
- route
67. What is the network byte order in Unix?
Answers:
- Little Endian
- Big Endian
- It is negotiated during connection.
- It is undefined.
68. Which of the following segments within the process address space are unique to each thread?
Answers:
- code.
- data.
- stack.
- bss.
69. How do threads created using pthread library share data between themselves efficiently?
Answers:
- They use one of the standard interprocess communication methods.
- They use sockets.
- They don’t need any special mechanism as they share the data segment.
- They use shared memory.
70. By convention, which of the following signals causes a daemon to reload its configuration?
Answers:
- SIGHUP
- SIGKILL
- SIGINT
- SIGCONT
71. Which of the following block sizes results in the best read/write performance for an IO intensive application?
Answers:
- 8192
- 4096
- 2048
- 1024
72. What is the name of the standard linker on Unix?
Answers:
- cc
- ldd
- ld
- ls
73. Which of the following is employed by the operating system to speed up file IO on a Solaris system.
Answers:
- Inode Cache
- DNLC
- Buffer Cache
- Page Cache
74. How is the stack trace of all the threads in a multi threaded Linux application obtained?
Answers:
- strace -f -p <procid>
- “backtrace” at the gdb prompt.
- “thread apply all ::stack” at the gdb prompt.
- “thread apply all backtrace” at the gdb prompt.
75. Which of the following creates an IPC message channel?
Answers:
- id = msgget(key, 0700|IPC_CREAT);
- id = msgget(key, 0700, IPC_CREAT);
- id = msgctl(key, 0700|IPC_CREAT);
- id = msgctl(key, IPC_CREAT, 0700);
76. Which of the following system calls can be used to get the metadata of a file?
Answers:
- open
- stat
- fcntl
- ioctl
77. Which of the following commands can be used to create a static (archive) library?
Answers:
- tar
- ar
- ld
- gcc
78. Which of the following system calls is specific to debugging?
Answers:
- truss
- fcntl
- strace
- ptrace
79. Which of the following commands can be used to compile a C file called “test.c” into an executable called “test”?
Answers:
- cc -o test test.c
- cc -g -S test.c
- cc test test.c
- cc -E test.c
80. Which of the following IO mechanisms allows greater performance to concurrent IO-intensive applications?
Answers:
- Memory Mapped IO
- Read Ahead
- Direct IO (Filesystem locking is skipped)
- Async IO.
81. What is the outcome of attempting an ioctl system call on a block device file?
Answers:
- The system returns ENOTTY.
- The ioctl succeeds and returns 0.
- The system returns EIO.
- The system returns ENXIO.
82. Which of the following system calls can be used to create device special files?
Answers:
- open
- mkfs
- touch
- mknod
83. If a process is terminated due to a SEGFAULT on a Solaris 9 system, what is the name of the core file that is created?
Answers:
- core
- corefile
- memdump
- coredump
84. Which of the following socket system calls creates a Unix Domain Socket connection?
Answers:
- socket(PF_UNIX, SOCK_STREAM, protocol)
- socket(PF_INET, SOCK_DGRAM, protocol)
- socket(PF_IPX, SOCK_RAW, protocol)
- socket(PF_LOCAL, SOCK_STREAM, protocol)
85. Which of the following system calls creates a named socket?
Answers:
- creat
- mknod
- bind
- socket
86. Which of the following shell operators is used to send the standard output of the first command to the standard input of the second command?
Answers:
- &
- ^
- >
- |
87. Which of the following C headers needs to be included for socket programming?
Answers:
- <socket.h>
- <sys/socket.h>
- <stdio.h>
- <stdlib.h>
88. Where are the DNS and search domains specified?
Answers:
- /etc/fstab
- /etc/nsswitch.conf
- /etc/resolv.conf
- /etc/hosts-
89. A process opens a file and forgets to close the file descriptor when it
exits. What is the result?
exits. What is the result?
Answers:
- It results in a resource leak.
- The OS calls exit on behalf of the process before it terminates the process resulting in all the resources being reclaimed.
- The OS garbage collector recovers the descriptor.
90. If a write system call fails and if errno is set to EFAULT, what does it signify?
Answers:
- The system encountered an IO error while doing the write.
- The file descriptor was illegal.
- The write buffer is not legal.
- The file was removed by another process while this write was being attempted.
91. Which of the following commands can be used to install the native software package SOFTpkg on a Solaris system?
Answers:
- tar -xvf SOFTpkg
- swinstall -s `pwd` SOFTpkg
- rpm -i SOFTpkg
- pkgadd -d . SOFTpkg