# Pb with ptty and domain

**URL:** <https://discuss.ocaml.org/t/pb-with-ptty-and-domain/16925>\
**Category:** Community\
**Created:** [July 8, 2025, 3:34am UTC](https://discuss.ocaml.org/t/pb-with-ptty-and-domain/16925 "2025-07-08T03:34:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![craff](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/craff/32/3281_2.png) [@craff](https://discuss.ocaml.org/u/craff)\
**Post date:** [July 8, 2025, 3:34am UTC](https://discuss.ocaml.org/t/pb-with-ptty-and-domain/16925/1 "2025-07-08T03:34:35Z")

</div>

Hello

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 ?

---

<div class="post-metadata">

**Author:** ![craff](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/craff/32/3281_2.png) [@craff](https://discuss.ocaml.org/u/craff)\
**Post date:** [July 8, 2025, 5:40am UTC](https://discuss.ocaml.org/t/pb-with-ptty-and-domain/16925/2 "2025-07-08T05:40:09Z")

</div>

By the way, the goal is to have an equivalent of node-pty in OCaml 5

---

<div class="post-metadata">

**Author:** ![craff](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/craff/32/3281_2.png) [@craff](https://discuss.ocaml.org/u/craff)\
**Post date:** [July 9, 2025, 9:38pm UTC](https://discuss.ocaml.org/t/pb-with-ptty-and-domain/16925/3 "2025-07-09T21:38:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [July 10, 2025, 12:52am UTC](https://discuss.ocaml.org/t/pb-with-ptty-and-domain/16925/4 "2025-07-10T00:52:30Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![avsm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/avsm/32/6_2.png) [@avsm](https://discuss.ocaml.org/u/avsm)\
**Post date:** [July 10, 2025, 7:45am UTC](https://discuss.ocaml.org/t/pb-with-ptty-and-domain/16925/5 "2025-07-10T07:45:35Z")

</div>

Eio has “fork actions” that run after a spawn for just this case: [eio\_linux 1.2 · OCaml Package](https://ocaml.org/p/eio_linux/1.2/doc/Eio_linux/Low_level/Process/index.html#val-spawn)

The latest Eio release also exposed the C header file for this so you can bind your own C functions to call post fork as well.
