I wand to exec a command in a pty. I have bidings for ptsname, I can not use fork because domain have started to be spwan. I could use
Unix.create_process, but I need to run a few commands before doing exec (like Unix.setsid and opening the slave_fd side of the pty). I also tried to call exec from another spawned domain. But this does not really work (setsid is not legal their)
.
Does anyone sees a way ?
I managed to write a C stub, similar to caml_unix_spawn, but creating the tty, running the process in the tty and returning the master_fd of the tty for the process. From this I get a fully fonctionnal terminal in my browser.
Do you think I should do a PR proposing a function Unix.create_process_tty similar to Unix.create_process.
A classic way to do this (that I’ve seen used with big-ass C/C++ multithreaded processes – webservers) is to create what is referred to in the biz as a “spawner”. This is a little process that you create early, before you start threading. Then that process and the big momma process talk to decide when the spawner will fork/exec children, they can use FD_PASS to pass filedescriptors down so the momma can read/write to the children, etc.
I was told by Stu Feldman, back in the day, that they did this with early versions of Make(1) simply to avoid the massive page-table-replication hit (early UNIX, eh).