Normally one sets up their file descriptors and then forks an exec and one can interact with the other program via the file descriptors. But after spawning a domain, it is no longer possible to call Unix.fork
. What is the recommended way to spawn and interact with another program in Ocaml 5?
These functions should be fine (IIRC they all use posix_spawn
).
Note that you’ll want to set CLOEXEC (and close parent handles as needed) on any file descriptors you pass if you plan to do IPC via the standard streams. I’ve been bitten by this several times because you no longer directly control the fork at this point.
Thank you. Are there any details on what the format of the environment is supposed to be for create_process_env
? Do I have to worry about escaping the values? Is the array strings of the form foo=bar
?
Last week I was working on a program that spawns processes from multiple domains using domainslib
and indeed I have seen indications that these functions do work. However I ran into an issue regarding how to control the working directory of the external processes. My previous implementation based on a temp Unix.chdir
broke down when used from within multiple domains in parallel. I ended up using shexp for now (pr).
Is there a more standard alternate to spawning processes that includes a cwd
argument? (e.g. Eio.Process
has one but I couldn’t find one in the stdlib).
Thank you for your help @dbuenzli