multithreading - 进程死锁,Unix命令?

标签 multithreading unix

我想知道如何知道一个进程的线程是否在 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/

相关文章:

linux - shell脚本中的Mongodb logrotate

c - 服务器中的 Leader/Follower pthread 实现

c# - 在 linux box 中托管 .net API

java - 破折号和参数是否有任何标准的命令行约定?

c - 特定线程内的自动/全局变量是否对其他线程可见

Unix shell 代码,可移植性足以在所有 shell 上运行

linux - 存储数组值时出现语法错误问题 Unix Solaris Korn Shell

c# - SynchronizationContext 和 InvokeRequired

Python - 如何不在构建线程步骤中启动线程

multithreading - 具有分层输出的堆栈跟踪