linux - 进行系统调用时检测键盘中断的linux选项
问题描述
通常,当我在终端中运行程序时,我可以使用控制 C 来停止它。当我编写一个在 while 循环内调用操作系统命令的程序时,其余代码执行得如此之快,以至于无法停止除了杀死pid之外的程序。我一直在做的方法是添加 1 秒的睡眠,但修复它不是一个好习惯。
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/
解决方案
推荐阅读
- java - 如何获取 FirebaseListAdapter 中存在的元素数量?
- php - 如何使用嵌套的 do while 循环从数据库中获取菜单和子菜单?
- flutter - 为什么在从文本字段获取文本后尝试将文本发送到另一个页面时出现错误。我为此使用 bloc
- oracle - 为什么我得到 PLS-00049:Apex 中的绑定变量错误
- c++ - 在 C++ 中从输入文件中读取
- javafx - JavaFX 关键帧实例化
- android - 如何在真机上启动我自己的 admob 应用
- c# - 下载 csv 文件时出现问题,我已经创建它但无法在 asp.net 中下载
- c# - 如何在其他函数中更改我的全局变量?C#
- vbscript - CreateObject("WScript.Shell").Run Path 带空格找不到文件