LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-23-2006, 09:49 PM   #1
yhus
Member
 
Registered: May 2004
Posts: 75

Rep: Reputation: 15
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
 
Old 05-28-2006, 11:34 PM   #2
deboom
LQ Newbie
 
Registered: Mar 2006
Posts: 4

Rep: Reputation: 0
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;
}
 
Old 05-28-2006, 11:43 PM   #3
deboom
LQ Newbie
 
Registered: Mar 2006
Posts: 4

Rep: Reputation: 0
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;
}
 
Old 05-28-2006, 11:48 PM   #4
yhus
Member
 
Registered: May 2004
Posts: 75

Original Poster
Rep: Reputation: 15
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
 
Old 05-30-2006, 09:49 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,609
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
"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...
 
Old 06-03-2006, 10:00 AM   #6
the_unforgiven
LQ Newbie
 
Registered: Apr 2006
Posts: 12

Rep: Reputation: 0
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
 
  


Reply


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
Compiling a Kernel Module for User Mode Linux Last Attacker Programming 1 04-13-2006 06:26 AM
kernel panic while running user mode linux nlatha Linux - Software 3 03-24-2006 11:51 PM
Interface between user mode and kernel mode santosh_pn Linux - Software 1 06-17-2005 07:20 AM
UML--->compiling user mode linux in kernel 2.6 waqasgujjar Red Hat 0 12-18-2004 03:20 PM
IPC between kernel and user mode bun_zee Programming 1 06-04-2004 12:08 PM

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

All times are GMT -5. The time now is 05:02 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