LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 01-11-2019, 02:46 AM   #1
ayyasprings
Member
 
Registered: Aug 2014
Posts: 118

Rep: Reputation: Disabled
Can we use kernel interface in application programs?


Hi,

Can we use kernel provided implementation interfaces in User space programs?

For example

Code:
#include <sys/sem.h>
int semctl(int sem_id, int sem_num, int command, ...);
int semget(key_t key, int num_sems, int sem_flags);
int semop(int sem_id, struct sembuf *sem_ops, size_t num_sem_ops);
were meant for user application development.

Instead can we use the following interfaces of kernel impementation of semaphore
Code:
#include<asm/semaphore.h>
void sem_init(struct semaphore *sem, int val);
void down(struct semaphore *sem);
int down_interruptible(struct semaphore *sem);
int down_trylock(struct semaphore *sem);
void up(struct semaphore * sem);
in user application program.

please reply. I am newbie to linux kernel.
 
Old 01-11-2019, 03:09 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
The kernel has an interface for applications, documented in section 2 of the manual. The reasons for providing this interface is the same as for any other software that provides a service: The interface is stable, whereas internal implementation can change from release to release (or bug fix to bug fix), and you don't want to allow processes to mess around in the kernel, thereby affecting other processes.

You can't use internal kernel functions in your application because you have no library that implements them. If you want to link your application with the kernel's semaphore library, this library depends on other kernel code, and in the end you link your application with the entire kernel. In other words, you create a new kernel that includes your application. I don't think this is your goal.

The real question is: What do you want to achieve? Why do you think you need the kernel's internal semaphore code?

Last edited by berndbausch; 01-11-2019 at 03:10 AM.
 
Old 01-11-2019, 03:18 AM   #3
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by ayyasprings View Post
Can we use kernel provided implementation interfaces in User space programs?
Yes, but through the C library (2) calls only (see man 2 <function> for details.
As your program runs in user space and the kernel in kernel space, no direct calls are possible (they have two different address ranges), that's why the standard library has these interface functions implemented.
I.e. READ(2) is the low-level call under FREAD(3)
and UNLINK(2) is what will be used at the lowest level by the 'rm' program.
 
  


Reply



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
[SOLVED] Can't "su", can't print, can't call cups's interface, can't update... JZL240I-U Linux - Software 15 07-28-2015 05:25 PM
[SOLVED] Running .sh programs, which application do I use? PBIteach Linux - Newbie 8 08-11-2011 10:52 AM
LXer: Arios: light interface and heavy application base in a ready to use Ubuntu remaster LXer Syndicated Linux News 0 12-29-2010 01:10 PM
how can i shutdown the PHYSICAL interface of an ethernet interface markraem Linux - Networking 2 04-12-2007 02:29 PM
WPA support through 'ndiswrapper' interface is deprecated; use 'wext' interface lavie Linux - Wireless Networking 1 12-04-2006 11:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration