














































































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
This exam simulates competency in building custom Linux device drivers, covering kernel subsystems, memory management, interrupts, concurrency, device trees, character vs. block drivers, and kernel module lifecycle management. Practical tasks involve debugging kernel logs, writing minimal drivers, handling hardware communication layers, and ensuring stability and security across kernel releases.
Typology: Exams
1 / 86
This page cannot be seen from the preview
Don't miss anything!















































































Question 1. Which kernel architecture best describes Linux? A) Microkernel B) Monolithic kernel C) Hybrid kernel D) Exokernel Answer: B Explanation: Linux uses a monolithic kernel where core services, device drivers, and file system code run in kernel space. Question 2. What is the primary purpose of a system call in Linux? A) To switch user processes to real‑time mode B) To provide a controlled interface for user space to request kernel services C) To allocate physical memory for user applications D) To compile kernel modules Answer: B Explanation: System calls are the only safe way for user‑space programs to request privileged kernel operations. Question 3. Which macro designates the entry point of a loadable kernel module? A) module_exit() B) init_module() C) module_init() D) cleanup_module() Answer: C Explanation: module_init() registers the function executed when the module is loaded.
Question 4. Which function is used to unload a kernel module? A) module_cleanup() B) module_exit() C) exit_module() D) cleanup_module() Answer: B Explanation: module_exit() specifies the function called when the module is removed. Question 5. How can a symbol defined in one module be used by another module? A) DECLARE_SYMBOL() B) EXPORT_SYMBOL() C) MODULE_DEPEND() D) LINK_SYMBOL() Answer: B Explanation: EXPORT_SYMBOL makes a kernel symbol visible to other loadable modules. Question 6. Which printk log level displays messages only when the kernel is in debug mode? A) KERN_EMERG B) KERN_WARNING C) KERN_DEBUG D) KERN_INFO Answer: C Explanation: KERN_DEBUG messages are shown only if the console log level includes debug output.
Question 10. Which type of device is accessed through read/write system calls on a character special file? A) Block device B) Network device C) Character device D) USB device Answer: C Explanation: Character devices provide byte‑stream access via read/write. Question 11. What principle separates hardware mechanism from driver policy? A) Encapsulation B) Modularity C) Mechanism‑policy separation D) Inheritance Answer: C Explanation: Mechanism‑policy separation keeps generic hardware handling separate from device‑specific decisions. Question 12. Which kernel structure represents an object in sysfs? A) kobject B) kset C) kclass D) kdevice Answer: A Explanation: kobject is the fundamental building block for sysfs entries.
Question 13. Which function is used to copy data from kernel space to user space safely? A) memcpy_to_user() B) copy_to_user() C) user_copy() D) get_user_data() Answer: B Explanation: copy_to_user validates the user pointer and performs the copy. Question 14. Which file_operations member is called when a process opens a device file? A) .read B) .open C) .write D) .ioctl Answer: B Explanation: The .open method is invoked during the open() system call on the device file. Question 15. Which macro is used to define an ioctl command that transfers data from user to kernel? A) _IOW B) _IOR C) _IOWR D) _IO Answer: A Explanation: _IOW indicates a write‑only ioctl where data moves from user to kernel.
Question 19. Which kernel synchronization primitive can be used in interrupt context? A) Mutex B) Semaphore C) Spinlock D) Completion Answer: C Explanation: Spinlocks are safe in interrupt context because they do not sleep. Question 20. Which atomic operation clears a bit in a bitmap? A) atomic_set_bit() B) clear_bit() C) test_and_set_bit() D) atomic_clear_bit() Answer: B Explanation: clear_bit() atomically clears the specified bit. Question 21. What is the main advantage of using a read‑copy‑update (RCU) mechanism? A) Prevents deadlocks in user space B) Allows readers to access data without locking while writers update a copy C) Provides faster context switches D) Simplifies DMA mapping Answer: B Explanation: RCU lets readers proceed lock‑free, improving scalability for read‑heavy data. Question 22. Which kernel API disables preemption for a short critical section?
A) preempt_disable() / preempt_enable() B) local_irq_save() / local_irq_restore() C) spin_lock_irqsave() / spin_unlock_irqrestore() D) mutex_lock() / mutex_unlock() Answer: A Explanation: preempt_disable() prevents the scheduler from preempting the current task. Question 23. Which of the following is NOT a bottom‑half mechanism? A) SoftIRQ B) Tasklet C) Workqueue D) Top‑half ISR Answer: D Explanation: The top‑half interrupt handler runs immediately; SoftIRQ, tasklet, and workqueue are bottom‑half mechanisms. Question 24. Which function schedules a workqueue item? A) schedule_work() B) queue_work() C) init_work() D) submit_work() Answer: B Explanation: queue_work(&my_wq, &my_work) places the work item on the queue for later execution. Question 25. Which timer API provides high‑resolution timers?
A) smp_wmb() B) smp_rmb() C) smp_mb() D) wmb() Answer: C Explanation: smp_mb() is a full memory barrier, ordering both reads and writes. Question 29. In PCI driver development, which function obtains a reference to a PCI device’s struct pci_dev? A) pci_get_device() B) pci_find_device() C) pci_register_driver() D) pci_probe_device() Answer: A Explanation: pci_get_device(vendor, device, from) searches the PCI bus and returns a pci_dev pointer. Question 30. Which macro declares a platform driver’s compatible device tree entry? A) OF_MATCH_PTR() B) MODULE_DEVICE_TABLE(of, ...) C) PLAT_DRIVER(of) D) DEVICE_OF_MATCH() Answer: B Explanation: MODULE_DEVICE_TABLE(of, my_of_match) exports the of_match table for device tree binding.
Question 31. Which structure represents a network interface in the kernel? A) net_device B) sk_buff C) netif_ops D) eth_dev Answer: A Explanation: struct net_device holds the state and operations of a network interface. Question 32. What is the purpose of NAPI in network drivers? A) To provide a new packet format B) To combine interrupt handling with polling for better performance under load C) To encrypt network traffic D) To manage wireless authentication Answer: B Explanation: NAPI mitigates interrupt storms by disabling interrupts and polling the receive queue. Question 33. Which API is used to allocate a DMA‑coherent buffer? A) dma_alloc_coherent() B) kmalloc() with GFP_DMA C) vmalloc() D) get_dma_page() Answer: A Explanation: dma_alloc_coherent() returns memory that is both CPU and device accessible without cache incoherency.
Question 37. In USB driver development, which descriptor defines endpoint characteristics? A) device descriptor B) configuration descriptor C) interface descriptor D) endpoint descriptor Answer: D Explanation: The endpoint descriptor specifies direction, type, and max packet size for a USB endpoint. Question 38. Which function registers a USB driver with the core? A) usb_register_driver() B) usb_register() C) usb_register_device() D) usb_register_interface() Answer: B Explanation: usb_register(&my_driver) informs the USB core about the driver’s callbacks. Question 39. Which kernel macro declares the license of a module? A) MODULE_AUTHOR() B) MODULE_DESCRIPTION() C) MODULE_LICENSE() D) MODULE_VERSION() Answer: C Explanation: MODULE_LICENSE("GPL") tells the kernel the licensing terms.
Question 40. Which function is used to create a sysfs attribute for a kobject? A) sysfs_create_file() B) kobject_create_and_add() C) sysfs_create_group() D) kobject_uevent() Answer: A Explanation: sysfs_create_file(&kobj, &attr) creates a file representing the attribute. Question 41. Which flag passed to kmalloc() requests physically contiguous memory? A) GFP_ATOMIC B) GFP_KERNEL C) GFP_DMA D) GFP_USER Answer: C Explanation: GFP_DMA ensures the allocation is within the DMA‑capable address range and physically contiguous. Question 42. What is the main difference between kmalloc() and vmalloc()? A) kmalloc allocates virtual memory; vmalloc allocates physical memory B) kmalloc returns physically contiguous memory; vmalloc returns virtually contiguous memory that may be non‑contiguous physically C) kmalloc can be used in interrupt context; vmalloc cannot D) vmalloc is faster than kmalloc Answer: B Explanation: kmalloc provides physically contiguous pages; vmalloc creates a contiguous virtual area backed by non‑contiguous pages.
Question 46. Which macro is used to define a module’s author? A) MODULE_AUTHOR() B) MODULE_DEVELOPER() C) MODULE_CREATOR() D) MODULE_MAINTAINER() Answer: A Explanation: MODULE_AUTHOR("Name") embeds author information. Question 47. Which field of struct file_operations is called when the user performs an ioctl on the device? A) .unlocked_ioctl B) .compat_ioctl C) .ioctl (deprecated) D) .control Answer: A Explanation: .unlocked_ioctl is the modern entry point for ioctl handling. Question 48. Which function can be used to delay execution for a given number of milliseconds inside a kernel thread? A) msleep() B) udelay() C) ndelay() D) sleep_on() Answer: A Explanation: msleep(msecs) puts the calling thread to sleep for at least the specified time.
Question 49. Which of the following is a valid reason to use a spinlock instead of a mutex? A) The critical section may block for I/O B) The code runs in process context and may sleep C) The lock is needed inside an interrupt handler where sleeping is illegal D) The lock protects a file system operation that may schedule Answer: C Explanation: Spinlocks are safe in interrupt context because they never sleep. Question 50. Which function registers a character device’s class for automatic udev node creation? A) class_create() B) device_create() C) class_register() D) Both A and B Answer: D Explanation: class_create() creates a class; device_create() creates the device node under that class, triggering udev. Question 51. Which flag passed to request_irq() requests a threaded interrupt handler? A) IRQF_SHARED B) IRQF_TRIGGER_RISING C) IRQF_ONESHOT D) IRQF_PERCPU Answer: C
Explanation: MODULE_DEVICE_TABLE(of, my_of_match) exports the compatible strings used by the device tree. Question 55. Which kernel routine is responsible for translating a virtual address to a physical address? A) virt_to_phys() B) phys_to_virt() C) __va() D) All of the above Answer: A Explanation: virt_to_phys() returns the physical address for a given kernel virtual address. Question 56. Which API provides a way to schedule a function to run after a specified delay in jiffies? A) init_timer() / add_timer() B) schedule_delayed_work() C) hrtimer_start() D) Both A and B can be used Answer: D Explanation: Both the classic timer API (init_timer/add_timer) and workqueue delayed work can schedule delayed execution. Question 57. Which field of struct pci_dev holds the BAR (Base Address Register) values? A) resource[] B) bar[] C) base_addr[]
D) mem_base[] Answer: A Explanation: pci_dev.resource[n] stores the start, end, and flags of each BAR. Question 58. Which function in the DMA API maps a scatter‑gather list for a device? A) dma_map_sg() B) dma_sync_sg_for_device() C) dma_unmap_sg() D) dma_map_page() Answer: A Explanation: dma_map_sg() prepares a scatter‑gather list for DMA transfers. Question 59. In block driver development, which function is called to submit a request to the block layer? A) blk_queue_make_request() B) submit_bio() C) blk_start_request() D) blkdev_queue_request() Answer: B Explanation: submit_bio() enqueues a BIO (block I/O) request for processing. Question 60. Which macro defines the major number for a dynamic character device allocation? A) MAJOR_DYNAMIC B) DYNAMIC_MAJOR C) 0 (passed to alloc_chrdev_region)