Kernel Programming Test (Solaris 2.x internals) Answers



1. How many LWPs must a process have to maximize its parallelism?
Answers:
• None
• Two
• It should be the same as the number of processors.
• It should be a factor of the available RAM.

2. Which of the following interfaces is used by the driver to signal the completion of an IO initiated by a strategy call?
Answers:
• biowait
• cv_broadcast
• biodone
• cv_signal
3. What does the vfs_vnodecovered field of a vfs structure indicate?
Answers:
• It points to the mounted on directory's vnode structure.
• It points to the root inode of the filesystem.
• It points to the root directory of the parent filesystem.
• It points to the vfs structure of the parent filesystem.
4. Which of the following commands can be used to examine and delete kernel breakpoints?
Answers:
• $b, :d
• ::break, ::delete
• $b, ::delete
• display break, delete break
5. Which of the following structures keeps track of the positional offset within the file where the next IO is to be performed?
Answers:
• struct file
• struct vnode
• struct inode
• struct proc
6. Which of the following structures describes the user initiated IOs?
Answers:
• struct buf
• struct file
• struct uio
• struct sio
7. Solaris rw locks are recursive locks. A thread that already holds a lock in the read mode can acquire the lock in the read mode
again.
Answers:
• True
• False
8. In which of the following driver interfaces should device instance specific resources be handled?
Answers:
• _init; _fini
• open; close
• attach; detach
• probe
9. Which of the following information must be tracked explicitly by a driver that allocates memory via kmem_alloc?
Answers:
• The address of the allocated memory.
• The size of the allocated memory.
• The alignment of the allocated memory.
• The thread that allocated the memory.
10. Is the solaris kernel fully preemtible?
Answers:
• Yes
• No
11. Which of the following operations results in the page cache being populated?
Answers:
• memory mapped IO
• read(2)/write(2) system calls
• opening a regular unix file.
• opening a socket.
12. Which of the following caches doesnot change its size dynamically on older solaris systems?
Answers:
• Page Cache
• Vnode Cache
• Inode Cache
• Buffer Cache
13. In which of the following contexts do callouts run?
Answers:
• User
• Kernel thread.
• LWP
• Interrupt.
14. Is the memory allocated by kmem_alloc paged?
Answers:
• Yes
• No
15. Which of the following kadb macros is useful in determining the panic address?
Answers:
• $<panic
• *panicstr
• $<msgbuf
• $r
16. What does the cv_wait_sig interface do?
Answers:
• It waits on the CV until the thread receives a specified external signal (sent via kill(2)).
• It waits on the CV until the thread receives a wakeup. It returns 0 if the thread receives an external signal (sent via kill(2)).
• It waits on the CV and ignores the specified signal but returns 0 if some other signal is received.
• It registers a call back with the kernel for the specified signal.
17. Why should floating point operations be avoided in drivers?
Answers:
• Because solaris does not support floating point operations at all.
• Because the sparc hardware does not support floating point operations.
• Because the kernel does not support floating point operations.
• Because they are expensive to perform.
18. Which of the following cache entries need to be purged/invalidated if a file is deleted?
Answers:
• DNLC
• Page Cache
• Buffer Cache
• Inode Cache
19. What is the correct way of deinitializing a mutex on solaris?
Answers:
• mutex_deinit(lock pointer)
• mutex_destroy(lock pointer)
• mutex_deinitialize(lock pointer)
• lockpointer-mutex_deinit()
20. What are the basic mutex operations supported by the solaris operating system?
Answers:
• Initializing and deinitializing the mutex
• Exclusively locking and unlocking the mutex
• Reader writer locking semantics on the mutex
• Try acquire mutex exclusive
21. Which of the following interfaces are invoked by the OS to flush all data belonging to a filesystem to a disk?
Answers:
• VOP_FSYNC
• VFS_SYNC
• VOP_PUTPAGE
• VOP_WRITE
22. What does the VOP_INACTIVE interface do?
Answers:
• It drops the reference count on a vnode.
• It deletes all data associated with a vnode.
• It drops the reference count on a vnode and if required it deletes all data associated with a vnode.
• It increments the reference count on a vnode.
23. What does the v_vfsmountedhere field of a vnode indicate?
Answers:
• If set to 1, it indicates that a filesystem is mounted on that vnode.
• It points to the root vnode of the filesystem to which the vnode belongs.
• It points to the vfs structure of the mounted on filesystem.
• It points to the root vnode of the mounted on filesystem.
24. Which of the following commands prints out the kernel device tree?
Answers:
• ls
• drvconf
• prtconf
• devlinks
25. The OS guarantees that a thread blocked on a cv via a cv_wait call does not wakeup prematurely and hence does not need to re-check for the reason for blocking.
Answers:
• True
• False
26. Which of the following interfaces needs to be implemented for a filesystem to support swap files?
Answers:
• VOP_WRITE and VOP_READ
• VOP_GETPAGE and VOP_PUTPAGE
• VOP_MAP and VOP_UNMAP
• VOP_PAGEIO
27. Which of the following interfaces can be used to avert a thundering herd of waiters?
Answers:
• cv_broadcast
• cv_signal
• cv_wakeall
• cv_wakeone
28. Which of the following components is responsible for speeding up file paths to inode lookups?
Answers:
• Page Cache
• DNLC
• Buffer Cache
• Vnode Cache
29. Which of the following is pageable?
Answers:
• kernel stack.
• user addresses.
• kernel heap.
• kernel code.
30. In which of the following contexts does the solaris kernel handle interrupts?
Answers:
• User context.
• LWP context.
• On a separate interrupt stack without any special context.
• In a kernel thread context.
31. What is the significance of setting the kernel global variable 'kmem_flags' to '0xf'?
Answers:
• It turns on buffer redzone (write past end of buffer).
• It turns on freed buffer checking.
• It turns on allocator auditing.
• It turns on uninitialized data checking.
• All of the above
32. Which of the following sequences correctly builds the loadable module 'mymod'?
Answers:
• cc mymod.c
• cc -o mymod.o mymod.c; ld -o mymod mymod.o
• cc -D_KERNEL mymod.c
• cc -D_KERNEL -o mymod.o; ld -r -o mymod mymod.o
33. Which of the following calls fits in at 'statement xxx'
to produce correct results in the code snippet below?

mutex_enter(mutex pointer);
while (condition is false) {
      cv_wait(cv pointer, mutex pointer);
}

statement xxx;
mutex_exit(mutex pointer);
Answers:
• mutex_enter(mutex pointer)
• mutex_exit(mutex_pointer)
• nothing needs to be done.
• cv_signal(cv pointer)
34. Which of the following locking sequences is correct?
Answers:
• rw_init; rw_enter; rw_destroy
• rw_enter; rw_destroy
• rw_init; rw_enter; rw_exit; rw_destroy
• rw_init; rw_tryenter; unconditional rw_exit; rw_destroy
35. What do the following mdb commands do?

::allocdby
::freedby
Answers:
• They are used to print the log of transactions on a particular memory location.
• They are used to print the log of transactions by a particular thread.
• They are used to print the slab cache that refers to the particular address.
• They are used to print the arenas that refer to the particular address.
36. Which of the following is true of memory allocated by kmem_alloc?
Answers:
• It is physical memory.
• It is virtual memory.
• It is pageable.
• It is a part of the global kernel heap.
37. On a solaris system with no special kmem_flag settings,
what happens when a thread running buggy code frees a buffer twice.
Answers:
• The results are unpredictable including a panic.
• The kernel fails the second kmem_free.
• The kernel kills the thread with a SEGFAULT.
• The second free is harmless as the kernel knows that the memory has already been freed.
38. Which of the following interfaces can be used by a driver interface routine to copy data from and to the user address space?
Answers:
• memcpy
• bcopy
• copyin;copyout
• memmove
39. Which of the following abstractions is the fundamental schedulable entity on a solaris machine?
Answers:
• User process.
• LWP.
• Kernel thread.
• Interrupt handler.
40. Which of the following adb/kadb commands can be used to determine the function which caused the panic?
Answers:
• $<msgbuf
• panic address?ia
• $r
• $C
41. Which of the following sets does a breakpoint at the start of the kernel function ufs_read?
Answers:
• ufs_read:b
• ufs_read!break
• ::break ufs_read
• ufs_read>break
42. Which of the following sparc instructions forms the basis of all other locking strategies?
Answers:
• lock
• ldstub
• movsb
• save
43. Can the mutex be locked by one kernel thread and unlocked by another kernel thread?
Answers:
• Yes
• No
44. What is the outcome if an interrupt handler needs to block on a resource?
Answers:
• The kernel will detect this situation and will panic the system.
• The system will hang.
• The interrupt handler will block until it can run again.
• None of the above.
45. Which of the following has the lowest scheduling latency?
Answers:
• User thread.
• Kernel thread.
• User Process.
• LWP.
46. Which of the following commands can be used to examine the panic stack trace?
Answers:
• $r
• $<msgbuf
• $C
• $<threadlist
47. Which of the following sparc instructions is employed before returning from a function to restore the original context?
Answers:
• restore
• pop
• revert
• ret
48. Which of the following kernel interfaces can be used by a driver interface like open to identify the specific device instance involved in the operation?
Answers:
• getmajor(dev_t)
• getminor(dev_t)
• open
• ((dev_t) dev) & 0xFFFF0000;
49. The memory allocated by kmem_alloc is private to the kernel thread that allocated it.
Answers:
• True
• False
50. Which of the following interfaces is the preferred way for drivers to log messages?
Answers:
• printf
• cmn_err
• dmesg
• log
51. How many times can a semaphore be acquired without blocking?
Answers:
• It depends on the count associated with the semaphore.
• 1
• 2
• 0
52. Which of the following firmware commands causes a kernel core file to be dumped to the dump device?
Answers:
• $sync
• sync
• dump
• $dump
53. What does the following kernel interface do?

rw_lock_held(lock pointer);
Answers:
• It checks if the lock is held in the read mode.
• It checks if the lock is held in the write mode.
• It does 'a' and locks it in the write mode.
• It does 'b' and locks it in the read mode.
54. Which of the following is true of the memory allocated by kmem_alloc?
Answers:
• It is double word aligned.
• It is pageable.
• It is zero initialized.
• Its availability is limited to the amount of physical memory.
55. Which of the following interfaces does the OS call to translate path names to vnodes?
Answers:
• VOP_LOOKUP
• VOP_READDIR
• VOP_GETPAGE
• VOP_READ
56. What is the driver configuration file for a 64 bit target module 'mymod'?
Answers:
• /kernel/drv/mymod.conf
• /kernel/drv/sparcv9/mymod.conf
• /etc/system
• /usr/lib/mymod.conf
57. The condition variable synchronization primitives need which of the following primitives to be employed by the client code to function correctly?
Answers:
• Reader-writer locks.
• Mutex
• Semaphore
• Spin lock
58. Which of the following kadb/adb commands prints the contents of the register set at a particular stack depth?
Answers:
• $<msgbuf
• $C
• $r
• $b
59. If there is contention between readers and writers on an rw lock, which of them are given preference over the other?
Answers:
• Readers
• Writers
• Neither (there is FCFS granting of locks).
• Both (there is one grant from either group).
60. Which of the following mechanisms enables solaris to support real time applications?
Answers:
• Hidden scheduling.
• Priority inheritance.
• Priority inversion.
• Interrupts.
61. Is the glock necessary if a filesystem does not implement the mmap interface?
Answers:
• Yes
• No
62. Is the thread allowed to perform any kind of blocking operation while holding a mutex?
Answers:
• Yes
• No
63. Which of the following kernel subsystems employs a semaphore for synchronization?
Answers:
• Inode Cache
• Buffer Cache
• Page Cache
• DNLC
64. What does the OS do when it detects a page fault on a valid address?
Answers:
• It calls the VOP_READ interface of the vnode to fetch the data.
• It calls the VOP_MMAP interface of the vnode to fetch the data.
• It calls the buffer cache get block interface to fetch the data.
• It calls VOP_GETPAGE interface of the vnode to fetch the data.
65. Which of the following kadb/adb macros can be used to examine the stack traces of all the kernel threads?
Answers:
• $<stack
• $<traceall
• $<threadlist
• $<msgbuf
66. The OS can unload a module automatically if needed.
Answers:
• True
• False
67. Which of the following kernel defined data types is involved in the interface calls to manipulate CVs?
Answers:
• kmutex_t
• kcondvar_t
• vnode_t
• page_t
68. Which of the following debuggers allow extensive customization and supports user written pluggable debugging modules?
Answers:
• adb
• dbx
• crash
• mdb
69. What is the command to boot into the kernel debugger (kadb) from an 'ok' prompt?
Answers:
• boot kadb
• kadb
• unix kadb
• go kadb
70. What happens if a driver running on a sparc processor tries to access a 32 bit quantity which is aligned on a 16 bit boundary?
Answers:
• The processor automatically handles this situation.
• The system panics.
• Such a driver code will not be compiled.
• Such a driver code will not be loaded.
71. What are the commands to load and unload the kernel module 'mymod'?
Answers:
• insmod mymod; rmmod mymod
• pkgadd mymod; pkgrm mymod
• modload mymod; modunload mymod
• modload mymod; modunload -i moduleid
72. What is the compiler option to generate a 64 bit binary loadable on a sparc machine?
Answers:
• -xarch=v5
• -xarch=v9
• -64
• -target=64
73. What is the kernel interface to initialize a reader writer lock?
Answers:
• readwrite_init(lock pointer)
• rw_initialize(lock pointer)
• rw_init(lock pointer)
• rw_enter(lock pointer)
74. Can the solaris semaphores be used in the interrupt context?
Answers:
• Yes
• No
75. What is the correct way of initializing a mutex on solaris?
Answers:
• mutex_init(lock pointer, lock name, type of mutex)
• mutex_init(lock pointer)
• mutex_enter(lock pointer)
• mutex_initialize(lock pointer)
76. On a sparc system, which of the register set of a calling function is passed on as input registers to the called function?
Answers:
• input
• output
• local
• global
77. What sequence of key strokes is required to trap into the kadb in a live session?
Answers:
• STOP-A on sun keyboards.
• send brk via a telnet session.
• CTRL-A on sun keyboards.
• tip b via a serial console session.
78. Which of the following abstractions enables a multi-threaded application to take advantage of the available parallelism?
Answers:
• User threads.
• LWP.
• Kernel threads.
• User processes.
79. Which of the following sequences involving a CV is correct if a thread wants to wait for an event?
Answers:
• cv_init; mutex_enter; cv_wait; mutex_exit; cv_destroy
• cv_init; cv_wait; cv_destroy
• cv_init; cv_signal; cv_destroy
• cv_init; cv_timedwait; cv_destroy
80. Which of the following is true if an interrupt thread needs to block on a resource?
Answers:
• Interrupt threads on solaris cannot block.
• They can be scheduled to run on a different processor once they are runnable.
• They are scheduled to run on the same processor.
• The system hangs.
81. Which of the following types of information is stored within the buffer cache?
Answers:
• Filesystem Metadata
• User Pages backed by files.
• Anonymous Pages.
• DNLC entries.
82. Which of the following interfaces to a block device driver does the filesystem use?
Answers:
• int strategy(struct vnode *);
• int strategy(struct buf *);
• void strategy(struct uio *);
• int strategy(struct file *);
83. Which of the following buffer structure fields specifies the direction of IO transfer, the transfer size and the virtual address of the data?
Answers:
• b_flags
• b_bcount
• b_un
• b_blkno
84. What does the VFS_ROOT interface do?
Answers:
• It takes a vnode and a vfs and markes (marks or makes?) the vnode as the root vnode for the filesystem.
• It returns the root vnode of the specified vfs.
• It returns the parent vnode of the specified vnode.
• It returns the parent vfs of the specified vfs.
85. Which of the following locks is used to serialize reads and writes on a vnode?
Answers:
• The global VFS lock.
• The locks on the page structures.
• The VOP_RWLOCK.
• The locks on the buffer structures.
86. Which of the following CV interfaces can be used to wakeup exactly one waiter?
Answers:
• cv_broadcast
• cv_wakeone
• cv_wakeall
• cv_signal
87. Which of the following does the OS use for caching user data?
Answers:
• Buffer Cache
• Inode Cache
• Page Cache
• DNLC
88. Where is the following memory allocation type typically
employed?

memp = kmem_alloc(size, KM_NOSLEEP);
Answers:
• In the user context code as a backend to malloc.
• In the kernel context where every place memory needs to be allocated.
• In the interrupt context.
• In the buffer cache.
89. Which of the following sparc instructions causes a register window context to be created?
Answers:
• ldstub
• save
• restore
• movrw
90. Following a panic and a core dump, what is done to recreate the core files for debugging?
Answers:
• Use dumpadm to create the core files.
• Use savecore to create the core files.
• Nothing needs to be done; the os guarantees that the core files are always saved.
• Use dd to move the core files from the dump device to the filesystem.
91. Which of the following interfaces is equivalent to acquiring a lock?
Answers:
• sema_v
• sema_p
• sema_init
• sema_lock
92. Which of the following interfaces must be implemented by every loadable driver?
Answers:
• _init; _fini
• _init; _fini; probe
• _init; _info; _fini
• _init; _fini; open; close
93. Is it possible to take a core dump of a live system?
Answers:
• Yes
• No