Chinaunix首页 | 论坛 | 博客
  • 博客访问: 177505
  • 博文数量: 82
  • 博客积分: 3005
  • 博客等级: 少校
  • 技术积分: 785
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-08 16:05
文章分类

全部博文(82)

文章存档

2012年(5)

2011年(18)

2010年(59)

我的朋友

分类: LINUX

2010-05-10 11:04:15

Dear all,
I have problem with sending the isgnal from kernel space to user space.
I am sending the PId by ioctl to the kernel module. So when i recieve an interrupt on com port i am recieving the data and trying to send the signal from kernel space to the user space as fallowing way.
/* Kernel code */
struct task_struct *p;
p = find_task_by_pid(pid_no);
send_sig(34,p,0);
/* in user space code */
pid = getpid();
/* send pid to kernel */
uart_sa.sa_handler = uart_signal_handler; /* uart_signal_handler is the function on recept of signal */
sigaction(34,&uart_sa,NULL);
i checked while dbugging i recive the signal in user space 34 but my PC does not goto the uart_signal_handler. My program is getting terminated.
Can anybody suggest the how to solve this. or any help will be greatly appriciated.
Thanks
Harsha S
? Unusual HPC performance--5x change in speed Kexec ?
Add new comment
communicate through netlinkso
Anonymous (not verified)onNovember 8, 2005 - 4:02am
communicate through netlinksocket
reply
RE: how to send signal from kernel space to user space
Anonymous (not verified)onDecember 5, 2005 - 6:37pm
/* in user space code */
pid = getpid();
/* send pid to kernel */
you can access a user process's pid with current->pid placed in a function which is called from user space, e.g poll, ioctl, mmap and so
and don't forget to include linux/sched.h
reply
SENDING SIGNAL FROM KERNEL TO USER
ajitR (not verified)onApril 14, 2007 - 12:24am
It is possible to give signal to a user level process. PID of the user level process to which signal
is to be given should be known and signal number should be known.
Kernel function :- kill_proc_info /usr/src/linux-2.6.8-24/kernel/signal.c
kill_proc_info(int sig, struct siginfo *info, pid_t pid)
Call this function in kernel module, this function is exported so that it can be used in module.
Pass signal number as first argument to this function, and this signal number should not be negative.
Then declare a member of structure siginfo. And fill fields of this structure as,
struct siginfo info;
info.si_signo = sig; ( FILL YOUR -ve (eg -14 for alarm )SIGNAL NUMBER HERE ) <<<========== IMP IMP IMP
info.si_errno = 0;
info.si_code = SI_USER;
info.si_pid = current->tgid;
info.si_uid = current->uid;
When you will call this function in an kernel module, process with specified PID will recieve the
signal. And signal handler will invoke its execution.
Example code:-
========= signal.c =====================
1 # include
2 # include
3 //# include
4 //# include "/usr/src/linux-2.6.8-24/kernel/signal.c"
5 //MODULE_LICENSE "GPL";
6
7 int init_module()
8 {
9 int i,res=0;
10 char msg1[80];
11 struct siginfo info;
12 printk(KERN_ALERT"\n HELLO WORLD!!");
13
14
15 info.si_signo = -14; // GIVE YOU SIGNAL NUMBER HERE!!!!!
16 info.si_errno = 0;
17 info.si_code = SI_USER;
18 info.si_pid = current->tgid;
19 info.si_uid = current->uid;
20
21 kill_proc_info(14, &info, 7640); // THIRD ARGUMENT HERE SHOULD BE YOUR PROCESS TO WHICH YOU WANT TO SIGNAL
22
23
24 return 0;
25 }
26
27 void cleanup_module()
28 {
29 printk(KERN_ALERT"\n Good bye world!!");
30 }
31
================= Makefile ======================================
1 obj-m += signal.o
2
3 all:
4 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
5
6 clean:
7 make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
=============== User process =========================================
1 /**********************************
2 Program :- To handle alarm signal.
3 0302051.
4 ***********************************/
5 #include
6 #include
7 #include
8
9
10 void fun1(int no)
11 {
12 putchar(10);
13 printf("Signal no %d is received\n",no);
14
15
16 }
17
18
19 int main()
20 {
21 int i;
22 signal(SIGALRM,fun1);
23 printf("My PID :- %d ", getpid());
24 alarm(5);
25
26
27
28
29
30
31
32 while(1);
33
34 return 0;
35 }
36
37
========================= Expected output ============================================
Procedure to run:-
1.Compile user process.
2.Run user process.
3.Note down the 'pid' of this process. <<<<<============== IMP IMP
4.Modify module code to write PID of user process in it.
5. 'make' module
6. Insert module
Output:-
Whenever you will insert module it will generate signal. You will see
message in the shell where you have run the user process.
reply
why signals?
strcmponApril 14, 2007 - 12:38am
why can't you just use device files like /dev/ttyS0? user space program open file and waits with select() or blocks in read and continues, when kernel writes data. you can even get a SIGIO.
reply
阅读(2129) | 评论(0) | 转发(0) |
0

上一篇:UML

下一篇:宏定义

给主人留下些什么吧!~~