glibc死锁复现
【环境安装】
virtualBox
CentOS Linux release 7.6.1810 (Core)
yum install yum-utils nss-softokn-debuginfo --nogpgcheck -y
debuginfo-install -y glibc bzip2-libs-1.0.6-12.el7.x86_64 cyrus-sasl-lib-2.1.26-17.el7.x86_64 freetype-2.4.11-10.el7_1.1.x86_64 glibc-2.17-78.el7.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.12.2-14.el7.x86_64 libcom_err-1.42.9-7.el7.x86_64 libcurl-7.29.0-19.el7.x86_64 libidn-1.28-3.el7.x86_64 libjpeg-turbo-1.2.90-5.el7.x86_64 libpng-1.5.13-5.el7.x86_64 libselinux-2.2.2-6.el7.x86_64 libssh2-1.4.3-8.el7.x86_64 libxml2-2.9.1-5.el7_1.2.x86_64 nspr-4.10.6-3.el7.x86_64 nss-3.16.2.3-5.el7.x86_64 nss-softokn-freebl-3.16.2.3-9.el7.x86_64 nss-util-3.16.2.3-2.el7.x86_64 openldap-2.4.39-6.el7.x86_64 openssl-libs-1.0.1e-42.el7.4.x86_64 pcre-8.32-14.el7.x86_64 xz-libs-5.1.2-9alpha.el7.x86_64 zlib-1.2.7-13.el7.x86_64
【测试程序】
// test.c
#include <pthread.h> #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <signal.h> void func(int sig) { printf("Signal deal!\n"); char* fmt2 =NULL; fmt2 = (char*)malloc(100); fmt2 = dgettext("pg", "debug_content"); } int main() { signal(SIGUSR1,func); printf("mydebug pid=%d\n",getpid()); sleep(10); char* fmt =NULL; fmt = (char*)malloc(100); fmt = dgettext("pg", "debug_content"); printf("mydebug end\n"); return 0; }
【测试方法】
1)gcc test.c -o test -pthread -g
2)运行./test
3)gdb attach $pid
(gdb) b pthread_rwlock_rdlock
运行到53行时,给进程发送kill -10 $pid,然后输入c继续跑
【运行结果】
此时进程死锁
1)kill -15 $gdb进程pid
2)gdb attach $pid, 看bt