关闭

return ERESTARTSYS 作用

标签: signalsystemapi测试
2237人阅读 评论(1) 收藏 举报
分类:

 

ERESTARTSYS is a part of the api between the driver and the 
signal-handling code in the kernel. It does not reach user-space (provided 
of course that it's used appropriately in the drivers :) 

When a driver needs to wait, and get awoken by a signal (as opposed to 
what it's really waiting for) the driver should in most cases abort the 
system call so the signal handler can be run (like, you push ctrl-c while 
running somethinig that's stuck in a wait for an interrupt). The kernel 
uses the ERESTARTSYS as a "magic" value saying it's ok to restart the 
system call automagically after the signal handling is done. The actual 
return-code is switched to EINTR if the system call could not be 
restarted. 

 

当进程在内核里,信号到来时先运行信号处理函数,接着继续运行内核程序。

驱动程序里如下这样使用:wait_event_interruptible()使进程睡眠,如果进程是被信号唤醒,则先执行信号处理函数,再接着重新执行驱动程序。

 

 28          wait_event_interruptible(wq,flag);

 29         if(signal_pending(current))

 30         {

 31                 printk(KERN_ALERT "process %s is waked by signal/n");

 32                 return -ERESTARTSYS;

 33         }

 

 

 

应用程序测试如下,利用时钟信号。

 

  8   static void sig_alrm(int signo)

  9  {

 10         printf("alrm time is over/n");

 11 }

 

 16   if(signal(SIGALRM,sig_alrm) == SIG_ERR)

 17  {

 18         printf("initial alrm clock error/n");

 19  }

 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:78983次
    • 积分:1106
    • 等级:
    • 排名:千里之外
    • 原创:26篇
    • 转载:29篇
    • 译文:0篇
    • 评论:18条