c++ - 如何停止在不同系统的 shell 中运行的进程?

标签 c++ qt shell

好的,所以我正在使用 qt-C++ 程序从我的主机系统执行我的 SBC6845 中存在的程序 ./led.sh。该程序基本上将我的 SBC 连接到我的主机系统。它相当于“ super 终端”或“Minicom”。我从 http://code.google.com/p/qextserialport/ 中的“qextserialport-1.2rc.zip”中获得了这个程序(示例代码)“uartassistant” .

我看到了这个链接:Running shell command in QT c++ in ubuntu ,同时搜索如何从 qt 程序内部执行 shell 命令。我尝试并成功执行了./led.sh。感谢链接。

我声明

void someaction(); // in the dialog.h

然后在 dialog.cpp 中添加这个

connect(ui->pushButton, SIGNAL(clicked()), SLOT(someaction()));

还有这个

void Dialog::someaction() {

QString command = "sh ./led.sh\r\n"; const char* command2;
command2 = command.toLocal8Bit().data(); port->write(command2);

我能够在我的 SBC 中制作 ledflash。

但是当我试图停止./led.sh时,问题出现了,我无法在uartassistant中这样做(错误,需要修改,仍然有效)。 但目前我正在尝试制作另一个 pushbutton_1 并在其中放入类似“Ctrl+Z”的内容并要求 ./led.sh 停止。 我遇到了一些其他链接,由于声誉低,我无法放置。 我不知道如何在 qt 应用程序中使用 SIGTERM/kill 选项[来自其他链接]并在单击按钮时执行。 假设我使用 kill,我将如何确定多个此类按钮操作的 pidof 并指定要杀死的人。

此外,我想补充一点,我的 SBC 有 ash [Almquist shell]。所以它是 Bourne shell 的低内存克隆,我不知道它是否支持退出 led.sh 的正常命令。

最佳答案

I have no idea how to use SIGTERM / kill option[from other links] inside qt app and execute on pushbutton click.

与这么多一样,Qt 为您提供了一个直观的抽象,让您不必担心任何这些,即 QProcess .在你的情况下你会想要这样的东西:

QProcess proc;
proc.start("led.sh");
...

//handle Ctrl-Z event
proc.close();

第一个答案here还有其他几种技术可以执行更复杂的 shell 命令。

关于c++ - 如何停止在不同系统的 shell 中运行的进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15766416/

相关文章:

c++ - 使用 C++ boost::spirit PEG 文法生成表达式

C++ 矩阵乘法不产生正确的输出

c++ - 如何从 C++ 中的 curl 输出中搜索所有出现的正则表达式?

c++ - 使 OpenGL 代码适应 Qt(特别是 keyPressEvent)

c++ - 二元运算符和重载、加法等

c++ - Qt - 错误 : unknown module networkauth

C++/Qt : Get files in directory ordered according to sorting currently applied in Windows Explorer

linux - 为一个程序保留 CPU 时间?

shell - 通过大文件逐步搜索

c - c 中的 shell 未按预期工作 - 与管道损坏相关