|
|
@@ -1,19 +1,19 @@
|
|
|
package containers
|
|
|
|
|
|
import (
|
|
|
+ "debug/elf"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
"log"
|
|
|
- "regexp"
|
|
|
- "debug/elf"
|
|
|
"os"
|
|
|
- "os/exec"
|
|
|
- "runtime"
|
|
|
+ "os/exec"
|
|
|
+ "regexp"
|
|
|
+ "runtime"
|
|
|
)
|
|
|
|
|
|
var libjvmRegex = regexp.MustCompile(`.*/libjvm\.so`)
|
|
|
|
|
|
-func GetExeType(pid uint32) string{
|
|
|
+func GetExeType(pid uint32) CodeType {
|
|
|
mapsFilePath := fmt.Sprintf("/proc/%d/maps", pid)
|
|
|
|
|
|
data, err := ioutil.ReadFile(mapsFilePath)
|
|
|
@@ -25,15 +25,15 @@ func GetExeType(pid uint32) string{
|
|
|
|
|
|
if libjvmRegex.MatchString(content) {
|
|
|
fmt.Println("is java process")
|
|
|
- return string("java")
|
|
|
- }else if isGoProcess(pid){
|
|
|
- return string("go")
|
|
|
+ return CodeTypeJava
|
|
|
+ } else if isGoProcess(pid) {
|
|
|
+ return CodeTypeGo
|
|
|
fmt.Println("is go process")
|
|
|
}
|
|
|
- return ""
|
|
|
+ return CodeTypeUnknown
|
|
|
}
|
|
|
|
|
|
-func isGoProcess(pid uint32) bool{
|
|
|
+func isGoProcess(pid uint32) bool {
|
|
|
path, err := getProcessPath(pid)
|
|
|
if err != nil {
|
|
|
fmt.Printf("无法获取进程路径:%s\n", err)
|
|
|
@@ -47,10 +47,10 @@ func isGoProcess(pid uint32) bool{
|
|
|
defer ef.Close()
|
|
|
|
|
|
gopclntabSection := ef.Section(".gopclntab")
|
|
|
- if gopclntabSection != nil {
|
|
|
- fmt.Println("is a go process")
|
|
|
- return true
|
|
|
- }
|
|
|
+ if gopclntabSection != nil {
|
|
|
+ fmt.Println("is a go process")
|
|
|
+ return true
|
|
|
+ }
|
|
|
return false
|
|
|
}
|
|
|
|