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 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试