doushang9172 2019-02-09 21:17
浏览 454

使用Golang启动正在运行的程序的另一个实例的好方法是什么?

I would like a Go program to start multiple processes which it will interact with. (I'm also undecided on what method of IPC to use, but perhaps that's another question)

On thing I've thought of is using os.Executable() to get the location of the running executable, and then the exec package to run a new instance of the program. I wonder if there's another way to do this without needing to query the path of the executable, or if this is even a behaviour I should worry about.

  • 写回答

2条回答 默认 最新

  • dongxi2014 2019-02-09 22:07
    关注

    Using os.Executable is the recommended way to find your program's own path in recent version of Go (see this older SO answer for details). And then you can use exec.Command to run more instances of it.

    It's rather unusual though, so I wonder what use case you had in mind here. Orchestrating multiple processes is tricky and needs to solve a real issue for you to be worth it, in my experience.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog