RedHat iTOps Tube

Monday, May 14, 2012

Kernel Module and Userspace communication Signals - SIGUSR1

Hello Everybody,



I am a newbie and wrote this piece of code, I am expecting to receive a message on user space after inserting kernel Module.. But I am not able to receive that message, anybody can please make me correct?



KERNEL MODULE PROGRAM:


Quote:









#include <linux/module.h>

#include <linux/kernel.h>

#include <linux/init.h>

#include <asm/siginfo.h>

#include <linux/rcupdate.h>

#include <linux/sched.h>

#include <linux/uaccess.h>

#include <linux/signal.h>



int init_module () {

int i=1, res = 4478;

char msg[80];

struct siginfo info;

int pid;

printk(KERN_ALERT"\nHello World..");



info.si_signo = -10;

info.si_errno = 0;

info.si_code = SI_USER;

info.si_pid = current->tgid;

// info.si_uid = current->uid;



send_sig_info(10, 4478, 1); /* 4478 is pid i am getting after running userspace program */

return 0;

}



void cleanup_module () {

printk(KERN_ALERT"\nGoodBye World");

}




USERSPACE PROGRAM:


Quote:









#include <stdio.h>

#include <stdlib.h>

#include <signal.h>



void fun1 (int no) {

putchar (10);

printf("Signal No. %d received.", no);

}



int main () {

int i=1 ;

signal(SIGUSR1, fun1);

printf("My PID is %d.\n",getpid());



while (i);

return 0;

}




Procedure to run:

Compiled userspace

Note down PID

Enter the PID into the kernel code and compile it using Makefile.



expected Output:

Whenever i insert module it must generate signal, and I must receive a message in the shell where i am running userspace program.



But I am not able to receive any message from kernel into userspace.



Can anyone please make me correct?



Sindhu..