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 }