[英]PS/2 keyboard won't send keypress interrupts, but does respond to commands
[英]When does the wait() function (in LINUX) respond to interrupts?
我有這樣的c代碼
int childid;
int parentid;
void siginthandler(int param)
{
// if this is the parent process
if(getpid() == parentid){
//handler code which sends SIGINT signal to child process
kill(childid, SIGINT);
}
else // if this is the child process
exit(0);
}
int main()
{
parentid = getpid(); // store parent id in variable parentid, for the parent as well as child process
int pid = fork();
int breakpid;
if(pid != 0){
childid = pid;
breakpid = wait();
printf("pid = %d\n", breakpid);
}
else
sleep(1000);
}
現在,當我運行此代碼時,父進程會等待,而子進程會休眠。 如果我現在中斷(通過按ctrl + c )父程序,UNIX(POSIX標准)文檔告訴我wait函數應返回-1,並將errno設置為EINTR。 但是,我的代碼實現會殺死子進程,因為父進程將SIGINT信號發送到子進程。 但是,令人驚訝的是,(在父進程中)等待不會返回pid = -1並且errno設置為EINTR。 相反,它返回被殺死的子進程的id。
對此有解釋嗎?
使用signal()
安裝信號處理程序時,會發生以下兩種情況之一
這兩個中的哪一個取決於您的平台,在您的平台上它是2
(可能,您沒有顯示任何安裝信號處理程序的代碼。)
如果您使用sigaction ()安裝信號處理程序,則可以使用SA_RESTART
標志控制所需的1
或2
行為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.