Hello all, what is the kotlin-native way to stop/k...
# kotlin-native
n
Hello all, what is the kotlin-native way to stop/kill another process ?
a
Hello! Why don’t you use
platform.posix.kill
?
n
@Artyom Degtyarev [JB] I am a total beginner in java/kotlin 🙄 But thanks for the hint 🙂
by the way - google doesn't ahow anything about this function - where can I read about it ?
n
is
platform.posix.kill
a java call ?
no red 2
I cannot find any example with
platform.posix.kill
🙄
a
It shall be used the same way as original system call. Input the process id and the signal code, get the result. To import this function, one should go with
import platform.posix.kill
or
import platform.posix.*
, if other contents of this platform library is desired.
Maybe this sample will make you more familiar with the posix library usage(https://github.com/JetBrains/kotlin-native/tree/master/samples/echoServer).
e
Note that
platform.posix.kill
is kotlin’s reference to the original
kill()
function from UNIX
signal.h
. Basically, if you want to find functions like this look for C libraries, not Java libraries. Here’s the documentation for the kill command: https://linux.die.net/man/3/kill Here’s a sample from the GNU user manual: https://www.gnu.org/software/libc/manual/html_node/Kill-Example.html Note that you likely want to use SIGTERM or SIGKILL if you want to stop a process.
👍 1
Also, if it’s a process you don’t own you’ll need to run your program as a privileged user, like
root
or via the
sudo
command
t
It’s something kind of difficult to get people to understand about K/N and Kotlin in general. Kotlin is not a JVM language, it’s a language with a JVM target (which kind of by default, makes it feel like a JVM language, but I digress) It makes it more difficult to understand the different too when the Kotlin platform SDK has so many Java mirroring classes and functions - but in general, you want to avoid thinking of K/N as something like GraalVM - it’s not Kotlin > Java > Native, it’s Kotlin > Native.
The lines get really blurry when doing Cocoa too - it just works like voodoo magic, makes it feel like just a Obj-C dialect, even though it’s not…
n
This Kotlin Native project shows how to use the kill function to terminate a process: https://gitlab.com/napperley/jmonitor
Posix API is available straight out of the box with the Kotlin Native Linux, and Mac OS targets.
n
@napperley thanks a lot ! This is what I needed ! 🙂