



















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A beginner-friendly but detailed practice exam covering kernel architecture, system calls, modules, debugging frameworks, kernel configuration, patch workflow, and interactions between user space and kernel space. Candidates analyze kernel logs, identify memory management behaviors, and walk through basic module-building exercises.
Typology: Exams
1 / 91
This page cannot be seen from the preview
Don't miss anything!




















































































Question 1. Which directory in the Linux kernel source tree contains architecture‑specific code? A) include/ B) drivers/ C) arch/ D) net/ Answer: C Explanation: The arch/ directory holds code that is specific to each supported CPU architecture (e.g., x86, arm, mips). Question 2. What is the purpose of the .config file in a kernel source tree? A) Stores compiled object files B) Lists all kernel source files C) Records user‑selected configuration options for the build D) Contains the kernel’s version string Answer: C Explanation: .config is generated by configuration tools (make menuconfig, etc.) and holds the symbolic configuration options that drive the build process. Question 3. Which make target builds only the kernel modules without rebuilding the core kernel image? A) make all B) make modules C) make bzImage D) make clean Answer: B
Explanation: “make modules” compiles all loadable kernel modules defined in the source tree, leaving the core kernel image untouched. Question 4. When cross‑compiling a kernel for ARM on an x86 host, which variable must be set to indicate the target architecture? A) $ARCH B) $CROSS_COMPILE C) $SUBARCH D) $TARGET Answer: A Explanation: $ARCH selects the architecture (e.g., arm, x86) for which the kernel is being built; $CROSS_COMPILE points to the toolchain prefix. Question 5. What does the command ‘make oldconfig’ do? A) Deletes the existing .config file B) Updates an old .config to the current source tree, prompting for new options C) Forces a full recompilation of the kernel D) Generates a default configuration without user interaction Answer: B Explanation: “make oldconfig” reads an existing .config, keeps unchanged options, and asks the user about any new configuration symbols introduced in the newer source. Question 6. Which file is the default bootable kernel image produced by the build system? A) vmlinux B) vmlinuz C) bzImage
A) Prints the message to the user console only B) Logs the message with error severity, visible via dmesg or syslog C) Sends the message to the kernel’s panic handler D) Writes the message to /proc/kmsg and then discards it Answer: B Explanation: KERN_ERR prefixes the message with the error log level; printk routes it to the kernel log buffer, viewable with dmesg or a logging daemon. Question 10. Which log level is the highest severity in the kernel’s printk hierarchy? A) KERN_WARNING B) KERN_DEBUG C) KERN_EMERG D) KERN_INFO Answer: C Explanation: KERN_EMERG indicates an emergency condition that will likely lead to system crash; it is the most severe level. Question 11. Which macro is used to declare a module parameter of type int named ‘debug’? A) module_param(debug, int, 0) B) MODULE_PARAM(debug, int) C) module_int(debug) D) MODULE_PARM_DESC(debug, "int") Answer: A Explanation: module_param(name, type, permissions) creates a tunable parameter; permissions 0 means it is not exposed in sysfs.
Question 12. What command lists currently loaded kernel modules? A) modprobe – l B) lsmod C) insmod – list D) rmmod – v Answer: B Explanation: lsmod reads /proc/modules and displays the name, size, and usage count of each loaded module. Question 13. Which kernel data structure is used to implement doubly linked lists? A) hlist_head B) list_head C) rbtree_root D) klist_node Answer: B Explanation: list_head is the core structure for the Linux kernel’s generic doubly linked list implementation. Question 14. Which macro initializes a list head named ‘mylist’? A) LIST_INIT(mylist) B) LIST_HEAD(mylist) C) INIT_LIST_HEAD(&mylist) D) LIST_CREATE(mylist) Answer: C
Answer: C Explanation: /proc is a pseudo‑filesystem that presents process and system information (e.g., /proc/meminfo) as regular files. Question 18. Which function creates a procfs entry named “myinfo” under /proc? A) proc_create("myinfo", 0, NULL, &my_fops) B) create_proc_entry("myinfo", 0, NULL) C) proc_mkdir("myinfo", NULL) D) proc_register("myinfo", &my_ops) Answer: A Explanation: In modern kernels, proc_create registers a file with given name, permissions, parent directory (NULL for /proc root), and file_operations. Question 19. Sysfs attributes are represented by which structure? A) struct proc_dir_entry B) struct kobject_attribute C) struct device_attribute D) struct attribute Answer: D Explanation: In sysfs, each attribute is a struct attribute (or a derived struct like device_attribute) that defines the name and permission bits. Question 20. Which ioctl command macro encodes a command that reads data from the kernel to user space? A) _IOW B) _IOR
Answer: B Explanation: _IOR encodes an ioctl command where data is copied from kernel (output) to user space (read). Question 21. What is a race condition in kernel programming? A) A deadlock caused by circular locking B) An event where two threads access shared data without proper synchronization, leading to unpredictable results C) A situation where interrupts are disabled for too long D) A condition where memory allocation fails repeatedly Answer: B Explanation: A race condition occurs when concurrent execution leads to nondeterministic outcomes because shared resources are not protected. Question 22. Which synchronization primitive should be used when a critical section may sleep? A) spinlock_t B) raw_spinlock_t C) mutex D) seqlock_t Answer: C Explanation: Mutexes allow the holder to sleep; spinlocks must not be held across sleepable contexts.
Question 26. What is the size of a normal memory page on a 64‑bit x86 Linux system? A) 2 KB B) 4 KB C) 8 KB D) 16 KB Answer: B Explanation: Standard page size on x86_64 is 4 KB (though huge pages exist, the default is 4 KB). Question 27. Which function is used to allocate memory that is suitable for DMA (physically contiguous)? A) kmalloc() B) vmalloc() C) dma_alloc_coherent() D) kzalloc() Answer: C Explanation: dma_alloc_coherent returns memory that is both virtually and physically contiguous and suitable for DMA operations. Question 28. Which kernel allocator is based on the slab caching mechanism? A) SLAB B) SLUB C) SLOB D) All of the above implement object caching, but SLAB is the original slab allocator. Answer: D
Explanation: The kernel provides several object‑caching allocators; SLAB is the original, while SLUB and SLOB are alternatives. Question 29. What does kmem_cache_create() return? A) A pointer to a newly allocated object B) A handle (struct kmem_cache *) representing a cache for a specific object size C) The number of objects currently in the cache D) An error code on failure Answer: B Explanation: kmem_cache_create creates a cache descriptor that can be used to allocate and free objects of a given size. Question 30. Which macro is used to declare a kernel timer variable? A) DECLARE_TIMER(my_timer) B) struct timer_list my_timer; C) TIMER_DECLARE(my_timer) D) DEFINE_TIMER(my_timer) Answer: B Explanation: Kernel timers are represented by struct timer_list; you declare a variable of that type. Question 31. How do you start a kernel timer to fire after 5 seconds? A) mod_timer(&my_timer, jiffies + 5 * HZ) B) timer_start(&my_timer, 5 * HZ) C) init_timer(&my_timer, 5 * HZ) D) schedule_delayed_work(&my_work, 5 * HZ)
D) spin_lock() Answer: C Explanation: msleep puts the calling thread to sleep, allowing other tasks to run, which is suitable in a thread context. Question 35. What is the purpose of the ‘make modules_install’ target? A) Compiles the kernel modules B) Installs compiled modules into /lib/modules/
B) kernel/sys.c C) fs/namespace.c D) drivers/char/tty_io.c Answer: A Explanation: Architecture‑specific entry.S files contain the low‑level syscall entry points and dispatch tables. Question 38. Which of the following is NOT a valid kernel log level prefix? A) KERN_DEBUG B) KERN_NOTICE C) KERN_ALERT D) KERN_VERBOSE Answer: D Explanation: KERN_VERBOSE is not a defined log level; the standard levels are EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG. Question 39. What does the ‘insmod’ command do? A) Inserts a module into the kernel and resolves its symbols B) Compiles a module from source C) Removes a module from the kernel D) Lists all available modules Answer: A Explanation: insmod loads a .ko file into the running kernel, performing symbol resolution and calling the module’s init function. Question 40. Which macro should be used to declare a module’s author?
Question 43. What is the effect of calling ‘synchronize_rcu()’? A) Forces a context switch B) Waits for all pre‑existing RCU read‑side critical sections to complete C) Disables preemption globally D) Flushes the CPU cache Answer: B Explanation: synchronize_rcu blocks until all RCU read‑lock sections that were active at the time of the call have finished. Question 44. Which of the following is a correct way to define a kernel thread function? A) int my_thread(void *data) { while (!kthread_should_stop()) … } B) void my_thread(void) { … } C) int my_thread(void) { … } D) void *my_thread(void *data) { … } Answer: A Explanation: Kernel thread functions return int and accept a void * argument; they typically loop while !kthread_should_stop(). Question 45. Which API is used to create a kobject for sysfs? A) kobject_create_and_add() B) sysfs_create_file() C) kobj_create() D) device_create() Answer: A Explanation: kobject_create_and_add creates a kobject, registers it with sysfs, and optionally places it in a parent directory.
Question 46. What does the ‘/proc/interrupts’ file display? A) List of active processes B) Number of interrupts per CPU and per interrupt line C) Kernel version information D) Memory usage statistics Answer: B Explanation: /proc/interrupts shows how many times each interrupt vector has been triggered on each CPU. Question 47. Which of the following is true about the ‘kmalloc’ function? A) It always returns physically contiguous memory B) It can sleep, so it may not be used in atomic contexts C) It allocates memory from the vmalloc area D) It is only available for x86 architectures Answer: B Explanation: kmalloc may sleep (e.g., when memory is low), therefore it cannot be called from atomic contexts like interrupt handlers. Question 48. Which kernel macro creates a read‑only sysfs attribute named “status”? A) DEVICE_ATTR_RO(status) B) SYSFS_ATTR_RO(status) C) KOBJ_ATTR_RO(status) D) ATTR_READONLY(status) Answer: A
Answer: A Explanation: The function registered with module_exit() is called during module unload. Question 52. Which of the following statements about ‘rcu_read_lock()’ is correct? A) It disables preemption on the current CPU B) It acquires a spinlock C) It may sleep D) It must be paired with rcu_read_unlock() in the same function Answer: A Explanation: rcu_read_lock disables preemption (and sometimes migration) to protect the read‑side critical section. Question 53. What is the purpose of ‘kobject_uevent_env()’? A) To create a sysfs file B) To send a uevent to userspace (e.g., udev) when a kobject changes state C) To allocate memory for a kobject D) To synchronize RCU callbacks Answer: B Explanation: kobject_uevent_env generates a netlink uevent that userspace tools can react to. Question 54. Which kernel API is used to schedule work to be executed in process context? A) schedule_work() B) queue_delayed_work() C) init_work() D) All of the above (they are related)
Answer: D Explanation: schedule_work queues a work_struct; queue_delayed_work does the same with a delay; init_work initializes the structure. Question 55. Which of the following is the correct way to declare a module’s description? A) MODULE_DESCRIPTION("Simple hello driver") B) module_desc("Simple hello driver") C) DESCRIPTION_MODULE("Simple hello driver") D) SET_MODULE_DESC("Simple hello driver") Answer: A Explanation: MODULE_DESCRIPTION records a textual description visible via modinfo. Question 56. What does the ‘/sys/class/net/eth0/address’ file contain? A) The IP address assigned to eth B) The MAC (hardware) address of eth C) The driver name for eth D) The link speed of eth Answer: B Explanation: The “address” attribute in sysfs for a network interface shows its hardware (MAC) address. Question 57. Which function can be used to obtain the current value of jiffies safely? A) get_jiffies() B) jiffies (direct read) – it is safe because it’s a volatile unsigned long C) read_jiffies()