内核阻塞函数中的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()使进程睡眠,如果进程是被信号唤醒,则先执行信号处理函数,再接着重新执行驱动程序。

 wait_event_interruptible(wq,flag);
  if(signal_pending(current))
  {
      printk(KERN_ALERT "process %s is waked by signal/n");
     return -ERESTARTSYS;
  }

应用程序测试如下,利用时钟信号。
   static void sig_alrm(int signo)
   {
       printf("alrm time is over/n");
  }
  if(signal(SIGALRM,sig_alrm) == SIG_ERR)
 {
       printf("initial alrm clock error/n");
 }
 

你可能感兴趣的:(内核阻塞函数中的ERESTARTSYS的定义)