LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-04-2012, 11:39 AM   #1
sindhu4sind
Member
 
Registered: Apr 2012
Posts: 38

Rep: Reputation: Disabled
Communicate between kernel and user space


Hello Everyone,

I am newbie in Linux and also with c language, but i am working on a project. so i have to do it

I am unknown of making communication between kernel module and user space..

I have got a kernel module, and implemented some of my scenarios.
* If any network card fails then i get the notification (This is working for kernel module)
Here is a snapshot for kernel module where i am able to get the process id:
Quote:
struct task_struct *id;
...
...
...
...
void hbmRxDo (void){

int nRemoteId, nLocalHostId;
unsigned char nNodeAvailable, bNetIsSplitted = 1;

..
..

if (nNodeAvailable > 0)
{
// Update Data-Path from PORT_A to PORT_A
if (pHbmList[nRemoteId].pathAA <= 0) {
gNetInfo.pConn[nRemoteId] &= 0xFE;
printk ("\t[%d].PORT_A <--> [%d].PORT_A is not available\n", nLocalHostId, nRemoteId);
id = get_current();
printk("Kernel PID : %d", id);
...
..
}
Now I am not sure either this is proper way or not. but i am able to get pid for each time failure in communication..

Now i have to do some tasks and i have no idea about this:

1. I need to transfer that information (for which i got the process id) to Userspace
2. After receiving the information on userspace i will transmit that information on to the user space of the other NODE via TCP/IP or UDP/IP.

Any suggestions or any example resembling to this scenario will be very much help full for me..

Thank you for your time in advance..

Sindhu
 
Old 05-05-2012, 04:02 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
So you are not familiar with linux, with c and with kernel.
Just a hint: the kernel cannot communicate itself with the userspace, but a userspace program can ask the kernel to provide some information. So you need to write a c program which will use this kernel module to get info.
 
Old 05-06-2012, 04:15 AM   #3
sindhu4sind
Member
 
Registered: Apr 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
Thank you pan64.. Not so much familiar with that kind of programming, can you please provide me some example?
 
Old 05-06-2012, 04:18 AM   #4
sindhu4sind
Member
 
Registered: Apr 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
i guess kill_proc() is the function which can share the pid

Quote:
kill_proc(id, SIGUSR1, 1);
If this function is carrying a signal to user space, then how to capture it on userspace? using ioctl!? but don't know the procedure!

---------- Post added 05-06-12 at 06:19 PM ----------

Any example will be really a good help if you can share..
 
Old 05-06-2012, 04:24 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
here is an example: http://www.ibm.com/developerworks/li...-system-calls/
You have your own kernel module, you just need to look at the part related to syscall
 
Old 05-06-2012, 09:27 PM   #6
sindhu4sind
Member
 
Registered: Apr 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
Thank you pan6. It seems helpful..
 
Old 05-09-2012, 08:03 AM   #7
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by sindhu4sind View Post
I am unknown of making communication between kernel module and user space..
There are functions named "copy_from_user" and
"copy_to_user" provided in the "kernel API documentation".
 
Old 05-09-2012, 09:22 AM   #8
sindhu4sind
Member
 
Registered: Apr 2012
Posts: 38

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Anisha Kaul View Post
There are functions named "copy_from_user" and
"copy_to_user" provided in the "kernel API documentation".
Thank you anisha kaul..
I actually developed further a userspace daemon also.
Here is my another post about that, with lots of confusion to communicate betweeen userspace and kernel using signals:
http://www.linuxquestions.org/questi...kernel-943991/


I am not a good programmer of C and also not so much familiar with Linux programming. everything there is new for me, i have just assigned a task by my professor which i am trying to complete.

Make me correct if i am creating wrong code also try to make it complete or give me some related example:
Quote:
/*Virtual Interface*/

int vif_ioctl (struct net_device* dev, struct ifreq *ifr, int cmd)
{
int ErrCode = 0;
struct pid_t pid;

struct host_info *pHostInfo, *uHostInfo;
struct net_info *pNetInfo, *uNetInfo;

switch (cmd) {
case SIOCSAFEDEVGETINFO:
/* some code */
break;
case SIOCSAFENETGETINFO:
/* some code */
case SIOCSAFEGETPIDINFO:
printk ("Get PID Info was callled. \n");
copy_from_user(pid, ?? , ??) //////////////////What i need to give arguments here in this function/////
break;
}
further in the kernel module following code is also implemented:
Quote:
..
static pid_t id;
int result;
..
int network_response()
{
...
...
if (x = 1)
{
printk("Failure of network.")
result = kill_proc(id, SIGUSR1,1);
printk("\nReporting failure detection %d\n", result);

}
if (x = 2)
{
printk("Failure of Node is detected.")
result = kill_proc(id, SIGUSR1,1);
printk("\nReporting failure detection %d\n", result);

}
}
I am confused that how kernel space will capture SIGUSR1 signals from userspace
May be my all discussion is not so much technical, or there you can find many mistakes in code. But pardon me I am not a technical person with this kind of stuff..
If any sample code or suggestions you have then I will be happy to hear that..
 
Old 05-09-2012, 10:00 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
the signal handler is part of the user space code. The kernel only sends the signal to the process, but it is handled by the process itself.
kill_proc will send a signal and you need to implement a signal handler to catch it. see here: http://www.gnu.org/software/libc/man...-Handling.html (and defining handlers)
 
1 members found this post helpful.
  


Reply

Tags
kernel module, pid, userspace



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
best way to communicate and synchronize between kernel and user space in linux mehulc87 Programming 1 12-16-2010 01:02 PM
Free user space pages of different user processes from inside kernel space trueskyte Linux - Kernel 1 10-22-2010 04:37 PM
Division of Logical Memory Space in to User Space and Kernel Space shreshtha Linux - Newbie 2 01-14-2010 09:59 AM
how to call socket prog code written in user space from kernel space???HELP kurt2 Programming 2 07-15-2009 09:56 PM
Netlink sockets usage to communicate b/w user and kernel space. vinodkr83 Linux - Newbie 1 07-03-2009 03:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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