Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Ruby中并行启动命令 我用Ruby编写了一个终端程序,用于一个用C++和java编写的程序集,它应该在分布式系统中执行。_Ruby_Linux_Multithreading_Exec - Fatal编程技术网

如何在Ruby中并行启动命令 我用Ruby编写了一个终端程序,用于一个用C++和java编写的程序集,它应该在分布式系统中执行。

如何在Ruby中并行启动命令 我用Ruby编写了一个终端程序,用于一个用C++和java编写的程序集,它应该在分布式系统中执行。,ruby,linux,multithreading,exec,Ruby,Linux,Multithreading,Exec,我想用ruby翻译此说明: 这是我的ruby代码: 我想创建一个线程池,每个线程执行该命令。这是合适的方式吗?正如我所研究的,线程不能执行“exec”,因为线程共享相同的内存地址。以下是解决方案: class Launcher def initialize(commands_list) #Expected to be an array of command string @commands_list = commands_list end def execut

我想用ruby翻译此说明:

这是我的ruby代码:

我想创建一个线程池,每个线程执行该命令。这是合适的方式吗?正如我所研究的,线程不能执行“exec”,因为线程共享相同的内存地址。

以下是解决方案:

class Launcher

  def initialize(commands_list)
    #Expected to be an array of command string
    @commands_list = commands_list
  end

  def execute
    p_threads = @commands_list.map do |command|
      Process.detach(Process.spawn(command))
    end
    p_threads.each(&:join)
   end
end

你知道GNU并行吗?它是为并行运行作业而设计的(令人惊讶!)。它是由经验丰富的人开发、测试和尝试的。您可能只是使用它,而不是重新实现它的大部分。或者,您可以查看一下它的手册和/或源代码,并从中学习。

您希望您的Ruby进程在启动所有功能后仍然有效吗?Ruby进程是否必须对这些命令的输出执行任何操作,或者等待它们完成?您好,Andrew,等待它们完成。每个进程至少有一个线程。据我所知,进程的所有线程都能够执行
exec
。尽管
exec()
将一个进程替换为另一个进程。这意味着所有属于旧进程的线程都消失了。它有ruby库吗?或者你是指使用反引号启动gnu parallel?你能解释一下如何将其扩展到集群吗?@Vicente环顾四周后,我认为你不能将gnu parallel用作库。您可以使用反引号、
system
Popen3
来调用它。我没有在集群上使用它的任何经验,但是您会想看看
class Launcher
   # Other method that we can ignore
   def order(command)
     @nodelist.each {#Do something here}
   end 
end 
class Launcher

  def initialize(commands_list)
    #Expected to be an array of command string
    @commands_list = commands_list
  end

  def execute
    p_threads = @commands_list.map do |command|
      Process.detach(Process.spawn(command))
    end
    p_threads.each(&:join)
   end
end