During the execution of the top command, if the user terminates the top command process by sending the SIG_TERM signal, the top command process may hang.
During the execution of the top command, if the user terminates the top command process by sending the SIG_TERM signal, the top command process may hang.
Write two scripts, top.sh and kill.sh.
top.sh
#!/bin/bash
while true
do
top -b -n 1 -p 1 > /dev/null
done
kill.sh
#!/bin/bash
while true
do
killall -15 top > /dev/null
done
run these teo scripts, top command will hang. The stack is as follows:
#0 futex_wait at ../sysdeps/nptl/futex-internal.h:146
#1 __GI___lll_lock_wait_private at lowlevellock.c:35
#2 __GI__IO_un_link at genops.c:59
#3 __GI__IO_un_link at genops.c:82
#4 _IO_new_fclose at iofclose.c:49
#5 close_stream at lib/fileutils.c:25
#6 close_stdout at lib/fileutils.c:37
#7 __run_exit_handlers at exit.c:113
#8 __GI_exit at exit.c:143
#9 bye_bye at top/top.c:577
#10 sig_endpgm at top/top.c:623
#11 <signal handler called>
#12 __GI__IO_link_int at genops.c:93
#13 _IO_new_file_init_internal at fileops.c:114
#14 __fopen_internal at iofopen.c:74
#15 cpus_refresh() ad top/top.c:2508
In the cpus refresh function, fopen will be called. If the signal SIG_TERM is responded to at this time, the exit function will be called in the signal processing function.deadlock occurs.
Edited by Craig Small