Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-30-2012, 07:07 AM   #1
LQ Newbie
Registered: Apr 2010
Posts: 16

Rep: Reputation: 0
semaphore usage in user and kernel level


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.
Old 11-09-2012, 10:06 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
  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.

Last edited by neonsignal; 11-09-2012 at 10:11 PM.


kernel, linux+, semaphores

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shared semaphore usage problem msherbiny Linux - Software 0 08-06-2009 07:57 AM
accessing SPI from kernel level and user level ramya_ts Programming 1 01-06-2009 07:30 AM
Find - battery life, CPU Usage,Wireless Signal Level , Congestion Level md_imranullah Programming 2 05-20-2008 08:45 PM
Sharing semaphore between kernel and user space balinju Programming 5 01-25-2008 12:21 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration