Linux - Kernel This forum is for all discussion relating to the Linux kernel. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-23-2006, 09:49 PM
|
#1
|
Member
Registered: May 2004
Posts: 75
Rep:
|
kernel and user mode communication
Hi,
I know that signal and fasync can be used between kernel and user mode, but it is not satisfied to be used in communication of kernel and user applications with multi-threading and processes. I would like to use message mechanism for communication between kernel and user mode, but I know IPC can not be used in kernel. Does anyone know any other alternative to user message communication between kernel device driver and user mode?
Thank you.
Jim
|
|
|
05-28-2006, 11:34 PM
|
#2
|
LQ Newbie
Registered: Mar 2006
Posts: 4
Rep:
|
umm..mm try this way
use
Code:
copy_from_user( .. )
in write function(your driver)
try to study this code as user space
Code:
//--- ignored header you should know by yourself ---
#define DEV "/dev/XXXX"
int main (int argc ,char **argv)
{
int dev;
int cmd;
dev = open (DEV ,O_RDWR);
if (dev < 0) {
printf ("Can't open device\n");
return -1;
}
if ( argc == 2 ){
cmd = atoi( argv[1] );
} else{
cmd = 2;
}
write (dev, &cmd, sizeof(int) );
sleep (3);
close (dev);
return 0;
}
|
|
|
05-28-2006, 11:43 PM
|
#3
|
LQ Newbie
Registered: Mar 2006
Posts: 4
Rep:
|
Code:
size_t
write_function (struct file *fd, const char *buf, size_t count, loff_t *d)
{
int cmd = 0;
void *arg = (void *)buf;
if ( copy_from_user((void *)&cmd, arg, sizeof(int)) )
return -EFAULT;
return 0;
}
|
|
|
05-28-2006, 11:48 PM
|
#4
|
Member
Registered: May 2004
Posts: 75
Original Poster
Rep:
|
Thanks for your response. But that just for user access kernel device driver. I actually want to find a way for kernel initiates a message to a specific user application or user thread when kernel receives an interrupt. Any luck for that solution?
Thank you.
Jim
|
|
|
05-30-2006, 09:49 PM
|
#5
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,315
|
"When the kernel receives an interrupt" is probably a bit too hasty. There are an awful lot of those...
The kernel can easily issue a signal to a running process, and this might well be the easiest way to handle any sort of asynchronous notification.
You can also have the user application open a virtual-device, and when you need to tell the user process something, just write to the device. udev does that...
|
|
|
06-03-2006, 10:00 AM
|
#6
|
LQ Newbie
Registered: Apr 2006
Posts: 12
Rep:
|
I don't know what your exact requirements are. But you could always use AIO (async I/O) which allows you to register callback functions for async notifications of I/O requests.
Check this: http://lse.sourceforge.net/io/aio.html
|
|
|
All times are GMT -5. The time now is 03:36 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|