Friday, June 20, 2014

Linux kernel interview questions - 1

I have listed few questions which gives basic idea of Linux kernel programming. Mostly kernel related interview is about the work you have done in past. For example, if you have done I2C & SPI drivers then most of the question is from those interfaces. If interviewer wants to know about your kernel knowledge, then he/she may ask general kernel related questions. I will update these questions on regular basis.

1. What is __init , __initdata ??

       These macros are used to mark some functions or initialized data (doesn't apply to uninitialized data) as "initialization" functions.The kernel can take this as hint that the function is used only during the initialization phase and free up used memory resources after.

__init will be defined as

#define __init   __section(.init.text) __cold notrace

and internally it will be expanded as

#define __section(S) __attribute__ ((__section__(#S)))

2. what is module_init() and module_exit() ??

These are macros which provides appropriate flags(boilerplates) to compiler for ensuring the treatment of init and cleanup functions.
Here it is defined. 

module_init and init_module of linux


           If programmer wants some symbols(function/data) to be used in other kernel modules, then those symbols should be exported using these macro. As name implies, EXPORT_SYMBOL_GPL() exports symbols only to GPL licensed modules.

4. What is modprobe, insmod, rmmod & depmod ?
5. What is initcall mechanism??
6. Which function will be the first function to be called in linux kernel?

No comments:

Post a Comment