LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   kernel and user mode communication (https://www.linuxquestions.org/questions/linux-kernel-70/kernel-and-user-mode-communication-447926/)

yhus 05-23-2006 09:49 PM

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

deboom 05-28-2006 11:34 PM

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;
}


deboom 05-28-2006 11:43 PM

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;
}


yhus 05-28-2006 11:48 PM

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

sundialsvcs 05-30-2006 09:49 PM

"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...

the_unforgiven 06-03-2006 10:00 AM

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 01:58 AM.