进行系统调用时检测键盘中断的linux选项

时间:2018-07-17 22:30:18

标签: linux keyboardinterrupt

通常,当我在终端中运行程序时,可以使用控件C停止它。 当我编写了一个在while循环内调用操作系统命令的程序时,其余代码执行得如此之快,以至于除了杀死pid之外没有其他方法可以停止该程序。我一直在做的事情是增加一秒钟的睡眠时间,但是解决这个问题不是一个好习惯。

while(!phrasespotted){
     invoke an operating system command to arecord for 5 secs, during which control C can not stop the program 
     process the audio for phrase spotting 
     sleep(1); //during this I can stop the program in terminal 
}

我应该在代码中添加些什么,以便它可以在进行系统调用时接收键盘中断,甚至可以注册该中断以在之后立即停止? 线程化是基于捕获信号的唯一选择吗? https://www.thegeekstuff.com/2012/03/catch-signals-sample-c-code/

0 个答案:

没有答案
相关问题