Re: Signals/ Communication from kernel to user!

From: Der Herr Hofrat (der.herr_at_hofr.at)
Date: 02/28/05

  • Next message: Stelian Pop: "Re: [patch 3/2] drivers/char/vt.c: remove unnecessary code"
    To: Ravindra Nadgauda <rnadgauda@velankani.com>
    Date:	Mon, 28 Feb 2005 20:13:30 +0100 (CET)
    
    

    >
    >
    > Hello,
    > We wanted to establish a communication from kernel module (possibly a
    > driver) to a user level process.
    >
    > Wanted to know whether signals can be used for this purpose OR there any
    > other (better) methods of communication??
    >
    a bit brute force but you can simply run through the task list and kick
    the pid of your user-space app (example for 2.4 kernel):

    hofrat

    ---snip---
    /*
     * Copywrite 2002 Der Herr Hofrat
     * License GPL V2
     * Author der.herr@hofr.at
     */
    /*
     * run through the task list of linux search for the passed pid and send it
     * a SIGKILL . run as insmod pid=# to send process with pid # a kill signal
     */

    #include <bits/signum.h> /* signal number macros SIGHUP etc. */
    #include <linux/kernel.h> /* printk level */
    #include <linux/module.h> /* kernel version etc. */
    #include <linux/sched.h> /* task_struct */

    MODULE_LICENSE("GPL v2");
    MODULE_AUTHOR("Der Herr Hofrat");
    MODULE_DESCRIPTION("Signal to a user-space app from a kernel module");

    int pid=0;
    MODULE_PARM(pid,"i");

    int
    ksignal(int pid,int signum)
    {
            struct task_struct *p;

            /* run through the task list of linux until we find our pid */
            for_each_task(p){
                    if(p->pid == pid){
                            printk("sending signal %d for pid %d\n",signum,(int)p->pid);
                            /* don't have a sig_info struct to send along - pass 0 */
                            return send_sig(signum,p,0);
                    }
            }
            /* did not find the requested pid */
            return -1;
    }

    int
    init_module(void)
    {
            /* send pid a SIGKILL */
            ksignal(pid,SIGKILL);
            return 0;
    }

    void
    cleanup_module(void)
    {
            printk("out of here\n");
    }
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Stelian Pop: "Re: [patch 3/2] drivers/char/vt.c: remove unnecessary code"

    Relevant Pages

    • Re: RFC [patch 13/34] PID Virtualization Define new task_pid api
      ... >> Any place the kernel saves a pid and then proceeds to signal it later. ... In the current patch that is not a problem, ... tty's send signals on hangup and f_setown can trigger signals ...
      (Linux-Kernel)
    • Re: how do threads work?
      ... >> A process cannot consider to switch task unless the flow of instructions ... >> kernel for a little help, in the form of regular timer signals. ... If you now ask, how does the kernel deliver signals, then we are no longer ...
      (comp.os.linux.development.system)
    • Re: Comments on the KSE option
      ... think M:N support in the kernel is a good idea. ... When the userland thread library issues a non-blocking ... When the userland thread scheduler switches threads ... It must also poll for blocked signals. ...
      (freebsd-current)
    • Re: RFC [patch 13/34] PID Virtualization Define new task_pid api
      ... >> Any place the kernel saves a pid and then proceeds to signal it later. ... > Through some method of signaling the kernel a ... A pointer to a task_struct while it kind of sort of works. ...
      (Linux-Kernel)
    • Re: Function: int recv (Socket, Buffer,Length, Flags) is returning with the error number 4
      ... That's a nice speculation by someone with little clue in kernel ... what it means from a kernel coding standpoint to "interrupt a system call". ... set to EINTR after the handler was run, there was no 'kernel state' to ... kernel can deliver signals at any time to a thread which is currently ...
      (comp.unix.programmer)