Embedded Linux Interview Questions on memory allocation and PID
This is part-2 of the Embedded Linux Questions which surely gonna help you in your professional interviews. Here we are going to discuss memory allocation, GFP_ATOMIC, null pointer dereference, etc...
How to allocate memory into the Linux Device Driver?
- kmalloc and vmalloc are used to allocate the memory into the kernel.
- kmalloc: It allocates the physical contiguous block of memory so the hardware device is very efficient to interact with the physical address that's why it used most of the time with appropriate flag GFP_ATOMIC and GFP_KERNEL.
- vmalloc: It allocates the virtual contiguous block of memory. this function is preferred when a large chunk of memory is required. It reduces the kernel performance as compare to kmalloc because remapping is required.
Where should be used the GFP_ATOMIC flag?
- GFP_ATOMIC flag used in kmalloc for the non-blocking calls. with this flag, kmalloc cannot go to sleep and the allocation step must be atomic.
- GFP_ATOMIC flag used in the Interrupt context.
- High priority and non-blocking call.
What is the effect of null pointer dereference in the Linux kernel?
- In the context of user space, the SIGSEGV signal send by the Linux kernel handler to the user space process.
- In the case of the Kernel task, you will get the oops message that causes the Kernel panic, and sometimes kernel crash also.
What is the PID 0 and PID 1 process in Linux?
- Swapper or sched process is the PID 0 process and it helps to start the paging in the kernel bootup.
- Init is the first process after the kernel boot up and also called as the PID 1 process. it invokes the many other process and demons.
What is the difference between /sys and /dev?
- /sys provides the device hierarchy information means how it connects to the system bus and also provides the manufacture details like Vendor ID and Product ID.
- /dev provides the interface to the programmer to access the device. /dev node is automatically created by the udev demon whenever you insert any hardware into the system (like USB storage ).