File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 7
7
import struct
8
8
from typing import Optional
9
9
10
- from psutil import NoSuchProcess , Process
10
+ from psutil import NoSuchProcess , Process , pids
11
11
12
12
from granulate_utils .linux .elf import read_elf_symbol , read_elf_va
13
- from granulate_utils .linux .process import is_kernel_thread
13
+ from granulate_utils .linux .ns import get_mnt_ns_ancestor
14
+ from granulate_utils .linux .process import is_kernel_thread , process_exe
14
15
15
16
16
17
def is_golang_process (process : Process ) -> bool :
17
- return not is_kernel_thread (process ) and get_process_golang_version (process ) is not None
18
+ return not is_kernel_thread (process ) and get_process_golang_version (process . create_time () ) is not None
18
19
19
20
20
21
@functools .lru_cache (maxsize = 4096 )
21
- def get_process_golang_version (process : Process ) -> Optional [str ]:
22
- elf_path = f"/proc/{ process .pid } /exe"
22
+ def get_process_golang_version (process_start_time : float ) -> Optional [str ]:
23
+ process = None
24
+ for pid in pids ():
25
+ if Process (pid ).create_time () == process_start_time :
26
+ process = Process (pid )
27
+
28
+ if process is None :
29
+ raise NoSuchProcess (process_start_time )
30
+ try :
31
+ exe = process_exe (process )
32
+ except :
33
+ return None
34
+ elf_path = f"/proc/{ get_mnt_ns_ancestor (process ).pid } /root{ exe } "
23
35
try :
24
36
symbol_data = read_elf_symbol (elf_path , "runtime.buildVersion" , 16 )
25
37
except FileNotFoundError :
You can’t perform that action at this time.
0 commit comments