内核阻塞函数中的ERESTARTSYS的定义

本文介绍了ERESTARTSYS在Linux内核中的作用及其如何用于处理驱动程序中的信号中断。通过具体示例,解释了如何在等待事件中处理信号,并在信号处理后重启系统调用。
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");
 }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值