B4J Question get process id ?

wl

Well-Known Member
Licensed User
Longtime User
For a b4j project running in ubuntu: is there a way to obtain the processid (pid) of the b4j project that is running ?

thanks !
 

billzhan

Active Member
Licensed User
Longtime User
B4X:
'Get pid of current Java process ; May not work on all JVM
' Tested: win 7 64bit ; ubuntu 14.04 lts 64bit ; mac os
'error -1 
'http://www.golesny.de/p/code/javagetpid
Sub getPID As Int
    Dim jo As JavaObject 
    jo.InitializeStatic("java.lang.management.ManagementFactory")
    Dim pidstr As String = jo.RunMethodJO("getRuntimeMXBean",Null).RunMethod("getName",Null) 
    pidstr = pidstr.SubString2(0,pidstr.IndexOf("@"))
    Dim pid As Int = -1
    If IsNumber(pidstr) Then
        pid = pidstr
    End If
    Return pid
End Sub
 
Upvote 0
Top