Is there a way to register a shutdown hook in nati...
# kotlin-native
m
Is there a way to register a shutdown hook in native? Equivalent with this on JVM:
Copy code
Runtime.getRuntime().addShutdownHook(Thread {
        println("shutting down")
    })
d
There's the POSIX `atexit`:
Copy code
import kotlinx.cinterop.staticCFunction
import platform.posix.atexit

fun doOnExit() {
    println("Exit!")
}

fun main() {
    atexit(staticCFunction(::doOnExit))
    println("Hello, Kotlin/Native!")
}
m
Thanks,
atexit
executes only on normal exit, I need it to be executed also on on SIGINT, which I managed to do using
Copy code
signal(SIGINT, staticCFunction<Int, Unit> {
        println("Exit!")
    })
147 Views