LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

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

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

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
  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 11:11 PM.
 
  


Reply

Tags
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 08:57 AM
accessing SPI from kernel level and user level ramya_ts Programming 1 01-06-2009 08:30 AM
Find - battery life, CPU Usage,Wireless Signal Level , Congestion Level md_imranullah Programming 2 05-20-2008 09:45 PM
Sharing semaphore between kernel and user space balinju Programming 5 01-25-2008 01:21 PM


All times are GMT -5. The time now is 10:49 PM.

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