gpt4 book ai didi

multithreading - 进程死锁,Unix命令?

转载 作者:行者123 更新时间:2023-12-02 02:29:33 24 4
gpt4 key购买 nike

我想知道如何知道一个进程的线程是否在 Unix/Linux 机器上死锁了?另外,是否有用于了解进程处于哪个阶段(或状态)的命令?如果你知道任何工具,请推荐。谢谢。

最佳答案

感谢/proc/<pid>/syscall ,这就是我最终实现 quick and dirty processes futex(op=FUTEX_WAIT) scanner 的方式.

#!/bin/bash
#
# Find all processes that are executing a futex(2) call with op=FUTEX_WAIT
# In some cases this can be helpful in finding deadlock-ed processes.
#

test ! $UID -eq 0 && echo -e "WARNING: Not running as root, only processes for this user are being scanned\n" >&2;
pids=$(ps -u $UID -opid --no-headers)

for pid in $pids; do
cat /proc/$pid/syscall |

awk "{if (\$1 == 202 && \$3 == \"0x0\") {
print $pid
}}";

# $1 is the syscall, we compare to 202 which is the futex call
# See: /usr/include/asm/unistd.h

# $2 is the 1st param, $3 is the 2nd param, etc
# We compare the second param to 0x0 which is FUTEX_WAIT
# See: /usr/include/linux/futex.h
done

关于multithreading - 进程死锁,Unix命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4298104/

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