Provide a way to avoid GC safepoint

I want to writing a library just like java.lang.ProcessBuilder
But I found it’s difficult to complete the project in pure Kotlin.
When I executing the following code, it’s hang…

val pid = fork()
if(pid == 0) GC.collect() else println(pid)

The new process(pid != 0) was hang on the GC collection…

Personally I don’t like the fork-exec, I prefer posix_spawn. But I found there’s no posix_spawn_file_actions_addchdir, which was published in POSIX 2024…

1 Like

I don’t think it’s really possible to tell what might cause GC.collect() to hang from your code ; from what’s on the screen it’s certainly not supposed to. You’d have to investigate more than this.

Also, trivially, why cause GC.collect() immediately after fork() ? There are not a lot of good reasons to cause a GC at specific points, since it eventually happens when necessary. I don’t think you elucidate why you want to do it at that point, and if the problem is that somehow it hang when you do it at this point and you can’t figure out why, then it becomes a relevant question to ask why do it at all.

1 Like

Because I don’t make sure there’re any unsafe (aka. signal-unsafe) actions during the fork-exec. The GC.collect() is just a simple way to reproduce the hang.

You may want to report this to https://kotl.in/issue. The forum is meant for community support, not for feature requests.

1 Like