通过线程启动Kill进程

时间:2015-08-01 04:58:57

标签: ruby multithreading unit-testing process

我有一个使用套接字进行通信的无头应用程序。启动时,它会保持活动状态,直到发送一条消息告诉它退出(或者崩溃,或者被杀死)。

当使用Ruby对该应用程序进行单元测试时,我需要启动该进程,与它进行交互(通过套接字),然后将其杀死。

我以为我可以使用这种模式来做到这一点:

class TestServer < MiniTest::Unit::TestCase
  def setup
    @thread = Thread.new{ `#{MY_COMMAND}` }
  end

  def test_aaa
    # my test code
  end

  def teardown
    @thread.kill if @thread
  end
end

但是,teardown代码会杀死该帖子,但不会杀死它启动的进程

如何以下列方式启动流程:

  1. 允许它在后台运行(立即将控件返回到我的Ruby测试工具)
  2. 如果需要,允许我稍后强制终止该过程。
  3. 我碰巧在OS X上开发,但如果可能的话,我会欣赏一个适用于Ruby运行的所有操作系统的通用解决方案。

1 个答案:

答案 0 :(得分:2)

您可以使用 private void xButton9_Click(object sender, EventArgs e) { Select_doctor Child_frm = new Select_doctor(); Child_frm.ShowDialog(this); // if() check for valid form here { string val = Child_frm.ReturnValue1; //values preserved after close string dateString = Child_frm.ReturnValue2; MessageBox.Show(Child_frm.ReturnValue1); } } 代替线程和反叛:

Process.spawn
相关问题