从 MATLAB GUI 中发送 SIGINT
在 MATLAB GUI 应用程序中,我启动了一个外部程序(Windows 上的控制台应用程序),负责从测量系统读取数据。数据存储在多个文件中,外部程序完成后,MATLAB 应用程序将立即处理这些文件。问题是这样的:
外部程序在命令行上运行时,可以通过发出 SIGINT(即按 Ctrl + C)来正常停止。信号处理程序捕获 SIGINT 并关闭程序。有没有办法通过按下“中止”按钮从 MATLAB GUI 应用程序中执行此操作?
经过几个小时的搜索,我偶然发现了 http://www.caam.rice。 edu/~wy1/links/mex_ctrl_c_trick/ 显示了如何检测 MEX 文件中的 SIGINT。让 MEX 调用外部程序可能会起作用(尽管我还不确定细节)。然而,它仍然需要 Ctrl + C 来停止程序。如何通过 GUI 中的按钮发送 SIGINT?
From within a MATLAB GUI application, I'm starting an external program (a console application on Windows) that takes care of reading data from a measurement system. The data is stored in several files that are processed by the MATLAB application as soon as the external program has finished. The problem is this:
The external program, when run on the command line, can be gracefully stopped by issuing a SIGINT (i.e. by pressing Ctrl + C). A signal handler traps the SIGINT and shuts down the program. Is there a way to do this from within the MATLAB GUI application, by pushing an "abort" button?
After many hours of searching I stumbled upon http://www.caam.rice.edu/~wy1/links/mex_ctrl_c_trick/ which shows how to detect SIGINT in a MEX file. Letting a MEX call the external program might work (although I'm not sure about the details yet). However, it still requires Ctrl + C to stop the program. How can I send the SIGINT via push button in my GUI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在 Cygwin 中启动外部程序,那么 Cygwin 将为它提供一个 PID。使用此 PID,您可以使用 Cygwin 的终止命令向进程发送信号。因此从 Cygwin 启动该程序。在 MATLAB 中,您可以使用
!ps
(其中 ! 表示调用外部 shell 命令)获取 Cygwin PID 列表,然后使用!kill -s signal pid
将信号发送到程序。要从 MATLAB GUI 实现这一点,请让某个按钮的回调调用!kill
。If you start your external program in Cygwin, then Cygwin will give it a PID. Using this PID you can use Cygwin's kill command to send signals to the process. So start the program from Cygwin. In MATLAB you can use
!ps
(where ! means call external shell command) to get a list of Cygwin PID's and then!kill -s signal pid
to send a signal to the program. To make it happen from a MATLAB GUI let the callback from some button call!kill
.