return ERESTARTSYS 作用

 

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  }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章