How to fire and forget a subprocess?

前端 未结 5 1284
深忆病人
深忆病人 2021-01-31 04:28

I have a long running process and I need it to launch another process (that will run for a good while too). I need to only start it, and then completely forget about it.

5条回答
  •  醉梦人生
    2021-01-31 05:17

    The other answers are good if you're sure you want to detach the child process. However, if you either don't mind, or would prefer to keep the child process attached (e.g. you are launching sub-servers/services for a web app), then you can take advantage of the following shorthand

    fork do
        exec('whatever --option-flag')
    end
    

    Providing a block tells fork to execute that block (and only that block) in the child process, while continuing on in the parent.

提交回复
热议问题