原 Linux中某个进程卡住,strace返回wait4(-1的解决办法
现象
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | [root@localhost ~]# ps -ef | grep pre root 38899 37747 0 12:27 pts/1 00:00:00 bash run_pre_install.sh root 38914 38899 0 12:27 pts/1 00:00:00 ssh -p 22 root@192.120.80.213 sh /soft/pre_install.sh root 38918 38917 0 12:27 ? 00:00:00 sh /soft/pre_install.sh root 39248 39173 0 12:33 pts/2 00:00:00 grep --color=auto pre [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# strace -p 38918 strace: Process 38918 attached wait4(-1, ^Cstrace: Process 38918 detached <detached ...> [root@localhost ~]# pstree -p 38918 sh(38918)─┬─grep(39075) └─more(39074) [root@localhost ~]# ps -ef | grep 39075 root 39075 38918 0 12:27 ? 00:00:00 grep -E AllowTcpForwarding|AllowAgentForwarding|PermitTunnel root 39254 39173 0 12:35 pts/2 00:00:00 grep --color=auto 39075 [root@localhost ~]# ps -ef | grep 39074 root 39074 38918 0 12:27 ? 00:00:00 more /etc/ssh/sshd_config root 39256 39173 0 12:35 pts/2 00:00:00 grep --color=auto 39074 [root@localhost ~]# more /etc/ssh/sshd_config | grep -E "AllowTcpForwarding|AllowAgentForwarding|PermitTunnel" #AllowAgentForwarding yes #AllowTcpForwarding yes #PermitTunnel no # AllowTcpForwarding no # AllowTcpForwarding no # AllowAgentForwarding no # PermitTunnel no AllowTcpForwarding yes AllowAgentForwarding yes PermitTunnel yes |
从 strace 输出来看,进程 38918 当前正在执行 wait4(-1, ...) 系统调用,这通常是进程在等待子进程退出时的状态。
wait4(-1, ...)表示进程正在等待任意一个子进程退出(-1是通配符,匹配任何子进程)。- 这是多进程程序的常见行为(如 shell 后台任务、服务进程派生子进程等)。
从 ps 和 grep 输出来看,问题出在 sshd 子进程(PID 39075)执行 grep -E 过滤 /etc/ssh/sshd_config 文件时卡住了,而父进程(PID 38918)正在 wait4 等待这个子进程结束。
解决
1 | [root@localhost ~]# kill -9 39075 39074 |
发现主进程退出了。


