LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   semaphore usage in user and kernel level (http://www.linuxquestions.org/questions/linux-software-2/semaphore-usage-in-user-and-kernel-level-4175434736/)

haribabu1836 10-30-2012 07:07 AM

semaphore usage in user and kernel level
 
Hi,

I was going through the semaphore's usage in linux and not yet get clear understanding on below things.

1. Is user and kernel level programming in Linux had different semaphore function calls?

2. what is the difference between "#include <linux/semaphore.h>" and "#include <semaphore.h>" files.

3. Can you please let me know where the user(applications) and kernel(modules) concepts differ in terms of programming on Linux.

Thanks in advance.

neonsignal 11-09-2012 10:06 PM

  1. In general kernel code cannot make use of any user space code. So while implementations of semaphores in user space simply make use of the operating system API for their implementation (ie, only indirectly using the kernel), inside the kernel code there has to be more direct use of interprocess primitives. The C interfaces could be made to look the same. But the kind of locking you might want to do in the kernel is not quite the same as in user code (so there are different primitives available), there's little attempt made to make them look the same.
  2. You would normally use <semaphore.h> in your program. The directory /usr/include/linux contains header information that is specific to interfacing with the kernel; it is still designed for user space code, but is not portable. You might need it if you require more specific API support.
  3. Programming in C for user applications and for the kernel differs because the context is different. In user space, the operating system takes care of process spawning, supports the primitives that the standard C libraries use for all I/O, provides the memory handling and security to ensure the proper separation of user processes, and so on. In monolithic kernel code, you have to be more aware of the context, since the support code you are using is not standard C libraries, but other components of the kernel. In the kernel, you are one level closer to the hardware, and do not enjoy the abstraction of the standard libraries.


All times are GMT -5. The time now is 02:08 AM.