2016-11-20 70 views
2

我正在尝试使用Linux/Bluez工具:hcitool,从QT进行BLE扫描。无法终止在Linux上运行hCitool的QProcess?

我使用以下方法来打开进程:

QString program = "sudo stdbuf -oL hcitool -i hci0 lescan"; 
hcitool = new QProcess(); 

connect(hcitool, SIGNAL(started()), this, SLOT(hcitool_started())); 
connect(hcitool, SIGNAL(finished(int)), this, SLOT(hcitool_finished(int))); 
connect(this, SIGNAL(kill_hcitool()), hcitool, SLOT(kill())); 
connect(this, SIGNAL(terminate_hcitool()), hcitool, SLOT(terminate())); 

hcitool->start(program, QProcess::Unbuffered | QProcess::ReadWrite); 

然后后来我汽车无从过程读取存储所有结果:

QString result = hcitool->readLine(); 

几秒钟后,我想停止hcitool进程,这是事情出错的地方。我试过终止信号,终止信号,把^ C写入进程,但没有任何效果。

其实kill信号完成该过程。但不是在事后,因为我hci0是抱了起来,我不能再次启动hcitool前hci0已经与重置一个好办法:

hciconfig hci0 down 
hciconfig hci0 up 

所以任何想法如何我可以终止这个过程吗?

+0

如果控制台的Ctrl-C正常工作,要做同样的事,你必须发送SIGINT信号,而不是SIGKILL。 –

+0

是的,那是我在QT中发送终止信号时发生了什么?..是否因为我通过“stdbuf”运行hcitool? – Jolle

+2

'另外,QProcess :: terminate'发送'SIGTERM'而不是'SIGINT'。你可以试试':: kill(hcitool-> processId(),SIGINT)'。 'stdbuf' *可能会成为一个问题,这取决于它如何处理信号。 –

回答

1

(从注释移动)

,通常工作是刚刚close()流,应该给一个SIGHUP或SIGPIPE子进程,这往往是处理得比较优雅的恶作剧。