将线程进程ID转换为十六进制格式

时间:2017-01-04 09:39:38

标签: java bash

我正在试图弄清楚哪个Java线程正在占用我的CPU。从我的顶级的角度来看,我发现这个LWP是瓶颈,占17.8%:

10634 user1+  20   0 6911624 939456  28016 S  0.3  17.8   0:00.65 java

据我了解线程的processid,应该映射Java Thread转储的 nid 属性:

"RMI Scheduler(0)" #209 daemon prio=9 os_prio=0 tid=0x00007fe71c18a800 nid=0x2c78 waiting on condition [0x00007fe6d35a5000]
"RMI TCP Accept-0" #207 daemon prio=9 os_prio=0 tid=0x00007fe714106000 nid=0x2c74 runnable [0x00007fe6d1f84000]
"Attach Listener" #206 daemon prio=9 os_prio=0 tid=0x00007fe7301ab800 nid=0x2a98 waiting on condition [0x0000000000000000]
"ServerService Thread Pool -- 67" #205 prio=5 os_prio=0 tid=0x00007fe74c126000 nid=0x2a49 waiting on condition [0x00007fe6d38a8000]
"Thread-94" #202 daemon prio=5 os_prio=0 tid=0x00007fe70c0c7800 nid=0x2a43 runnable [0x00007fe6ce995000]
"Weld Thread Pool -- 5" #192 prio=5 os_prio=0 tid=0x00007fe6f8116000 nid=0x2a32 waiting on condition [0x00007fe6ced97000]
. . . . . . . .

但是,将10640转换为十六进制不会产生有效匹配:

printf -v result1 "%x" "10640"
$ echo $result1
2990

你能帮忙将pid(10634)转换为有效的十六进制值,如nid属性所示? 感谢

1 个答案:

答案 0 :(得分:4)

实际上,2990是(十进制)10640的十六进制表示。也许你只希望0x前缀与C / Java / Python表示法一致

 $ printf -v result1 0x%x 10640
 $ echo $result1
 0x2990

 $ printf 0x%x 11340
 0x2c4c

为了完整性:您可以看到this question with its answers以了解如何查找由linux上的进程生成的本机线程ID。