Nathan Fallet
10/31/2025, 11:59 AMNathan Fallet
10/31/2025, 1:26 PMephemient
10/31/2025, 6:22 PM_exit() and not exit() on the fork child, and also I would not fork() from Kotlin/Native - it creates a new process with one thread, so it's missing everything else the Kotlin/Native runtime expects to exist, such as the GC thread, which could lead to some difficult-to-debug issues. consider using posix_spawn insteadloke
11/01/2025, 6:19 AMposix_spawn. Here's my implementation, which is think is mostly correct. https://codeberg.org/loke/array/src/branch/master/array/src/linuxMain/kotlin/com/dhsdevelopments/kap/io.linux.kt#L361loke
11/01/2025, 6:21 AMdup3() and pipe2()ephemient
11/01/2025, 7:48 AMfork, to reduce the chance of triggering or waiting for GC which will not work inside the child. even then, it's still not safe because you don't know which system and library calls the rest of the Kotlin runtime will makeephemient
11/01/2025, 7:50 AMA process shall be created with a single thread. If a multi-threaded process callsasync signal-safe operations being a key concept that is not guaranteed in Kotlin, the new process shall contain a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, the application shall ensure that the child process only executes async-signal-safe operations until such time as one of thefork()functions is successful.exec
ephemient
11/01/2025, 7:53 AMposix_spawn isn't reliable, I'd write a similar wrapper in C and use cinterop to call it from Kotlinloke
11/01/2025, 7:59 AMexec call failed.loke
11/01/2025, 7:59 AMloke
11/01/2025, 8:01 AMvfork would address this, since it blocks the parent process, but that also is not reliable since the standard says the child is not allowed to modify any data, which obviously a GC will. Is there a way to block GC calls?loke
11/01/2025, 8:02 AMephemient
11/01/2025, 8:21 AMloke
11/01/2025, 8:40 AMvfork?ephemient
11/01/2025, 8:47 AMfork or vfork at that point, the limitations of both are easier to handle in CNathan Fallet
11/01/2025, 10:08 AMOleg Yukhnevich
11/01/2025, 12:31 PMloke
11/01/2025, 2:01 PMloke
11/01/2025, 2:02 PMloke
11/01/2025, 2:02 PMNathan Fallet
11/01/2025, 3:06 PMOleg Yukhnevich
11/01/2025, 4:14 PMdo you know if it will implemented in an official packageI'm not aware of any plans at this moment. Feel free to check the roadmap; the focus on libraries is a bit different at this moment. Also, I haven't really found an issue in kotlinx-io or in the kotlin YT about support for
process functionality. So it's not even clear how popular it is 🙂
using third party project like the one you mentioned is the long term and production ready way?It's up to you to decide. I haven't really used the library, so I can't judge it. I just recently discovered it.