gpt4 book ai didi

linux - 使用 `ps -T -p [pid]` 时如何获取整个线程名称

转载 作者:行者123 更新时间:2023-12-04 19:30:29 25 4
gpt4 key购买 nike

ps -T -p [pid]top -H -p [pid] 只能显示前 15 个字符,如 http-nio-8080 -e,但我想获取整个线程名称,如http-nio-8080-exec-9,我该怎么办?谢谢!

例如:

[root@localhost ~]# ps -T -p 2251
PID SPID TTY TIME CMD
2251 2251 ? 00:00:00 java
2251 2808 ? 00:00:03 java
2251 2821 ? 00:00:00 VM Thread
2251 2822 ? 00:00:00 Reference Handl
2251 2823 ? 00:00:00 Finalizer
2251 2824 ? 00:00:00 Signal Dispatch
2251 2825 ? 00:00:02 C2 CompilerThre
2251 2832 ? 00:00:02 C1 CompilerThre
2251 2835 ? 00:00:00 Sweeper thread
2251 2851 ? 00:00:00 Service Thread
2251 2866 ? 00:00:00 VM Periodic Tas
2251 2867 ? 00:00:00 Common-Cleaner
2251 6518 ? 00:00:00 Catalina-utilit
2251 6520 ? 00:00:00 Catalina-utilit
2251 6531 ? 00:00:00 container-0
2251 7370 ? 00:00:00 NioBlockingSele
2251 7374 ? 00:00:00 http-nio-8080-e
2251 7375 ? 00:00:00 http-nio-8080-e
2251 7376 ? 00:00:00 http-nio-8080-e
2251 7377 ? 00:00:00 http-nio-8080-e
2251 7378 ? 00:00:00 http-nio-8080-e
2251 7379 ? 00:00:00 http-nio-8080-e
2251 7380 ? 00:00:00 http-nio-8080-e
2251 7381 ? 00:00:00 http-nio-8080-e
2251 7382 ? 00:00:00 http-nio-8080-e
2251 7383 ? 00:00:00 http-nio-8080-e
2251 7384 ? 00:00:00 http-nio-8080-C
2251 7395 ? 00:00:00 http-nio-8080-A

[root@localhost ~]# top -H -p 2251
top - 12:00:38 up 15 min, 1 user, load average: 0.06, 0.11, 0.19
Threads: 28 total, 0 running, 28 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 3880412 total, 2276824 free, 903836 used, 699752 buff/cache
KiB Swap: 1581052 total, 1581052 free, 0 used. 2745864 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2251 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.07 java
2808 root 20 0 3043676 152880 14232 S 0.0 3.9 0:03.00 java
2821 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.27 VM Thread
2822 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 Reference Handl
2823 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 Finalizer
2824 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 Signal Dispatch
2825 root 20 0 3043676 152880 14232 S 0.0 3.9 0:02.76 C2 CompilerThre
2832 root 20 0 3043676 152880 14232 S 0.0 3.9 0:02.07 C1 CompilerThre
2835 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.01 Sweeper thread
2851 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 Service Thread
2866 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.74 VM Periodic Tas
2867 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 Common-Cleaner
6518 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.02 Catalina-utilit
6520 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.12 Catalina-utilit
6531 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 container-0
7370 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.05 NioBlockingSele
7374 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.14 http-nio-8080-e
7375 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-e
7376 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.03 http-nio-8080-e
7377 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-e
7378 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-e
7379 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-e
7380 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-e
7381 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-e
7382 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-e
7383 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-e
7384 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.06 http-nio-8080-C
7395 root 20 0 3043676 152880 14232 S 0.0 3.9 0:00.00 http-nio-8080-A

它只能显示前 15 个字符,如 http-nio-8080-e,我想获取整个线程名称,如 http-nio-8080-exec-9,我该怎么办?


"http-nio-8080-exec-9" #25 daemon prio=5 os_prio=0 cpu=0.13ms elapsed=1013.48s tid=0x00007fc0708d9000 nid=0x1f waiting on condition [0x00007fc0506b1000]
java.lang.Thread.State: WAITING (parking)
at jdk.internal.misc.Unsafe.park(java.base@11.0.2/Native Method)
- parking to wait for <0x00000000c5c22c20> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(java.base@11.0.2/LockSupport.java:194)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(java.base@11.0.2/AbstractQueuedSynchronizer.java:2081)
at java.util.concurrent.LinkedBlockingQueue.take(java.base@11.0.2/LinkedBlockingQueue.java:433)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:107)
at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:33)
at java.util.concurrent.ThreadPoolExecutor.getTask(java.base@11.0.2/ThreadPoolExecutor.java:1054)
at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@11.0.2/ThreadPoolExecutor.java:1114)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@11.0.2/ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(java.base@11.0.2/Thread.java:834)

最佳答案

线程名称长度限制为 16 个字符(包括终止空字节 \0)。如果包括 \0 在内的长度超过 16 个字节,则字符串会在存储前被截断

参见 pthread_setname_npproc.5 -> 找到 /proc/[pid]/task/[tid]/comm

相关:
How to get the full executable name of a running process in Linux

关于linux - 使用 `ps -T -p [pid]` 时如何获取整个线程名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62295709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com