首页 > 解决方案 > 在adb shell中,执行exit命令会杀死android Q系统中的后台脚本

问题描述

  1. 我在后台运行 adb shell 脚本,例如:sh /data/test.sh &。线程 pid 为 2442

  2. 之后,我运行 exit 命令。后台脚本线程将被杀死。

我不知道如何解决这个问题。

shell 后台线程应该忽略 SIGHUP 信号。


更多信息:

ps -A | grep -E "2442|1007|978"                                                       
root           978     1  134760   4860 poll_schedule_timeout 0 S adbd

root          1007   978   33492   2916 sigsuspend          0 S sh

root          2442  1007   33492   3168 0                   0 R sh

我获取信号:

 # strace -p 2442                                                  
strace: Process 2442 attached
--- SIGHUP {si_signo=SIGHUP, si_code=SI_USER, si_pid=1007, si_uid=0} ---
rt_sigreturn({mask=[RTMIN]})            = 264
rt_sigprocmask(SIG_BLOCK, [CHLD RTMIN], [RTMIN], 8) = 0
rt_sigprocmask(SIG_SETMASK, [RTMIN], [CHLD RTMIN], 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD RTMIN], [RTMIN], 8) = 0
madvise(0x74a7648000, 4096, MADV_DONTNEED) = 0
madvise(0x74a7624000, 4096, MADV_DONTNEED) = 0
fcntl(3, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(4, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(5, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(6, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(29, F_GETFD)                      = -1 EBADF (Bad file descriptor)
fcntl(30, F_GETFD)                      = -1 EBADF (Bad file descriptor)
fcntl(31, F_GETFD)                      = -1 EBADF (Bad file descriptor)
close(2)                                = 0
close(1)                                = 0
close(0)                                = 0
mprotect(0x74a8298000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x74a8298000, 4096, PROT_READ) = 0
mprotect(0x74a8298000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x74a8298000, 4096, PROT_READ) = 0
munmap(0x74a8298000, 4096)              = 0
exit_group(129)                         = ?
+++ exited with 129 +++

和父信号信息:

strace -p 1007                                                  
strace: Process 1007 attached
read(0, "\4", 1)                        = 1
write(2, "^D\r\n", 4)                   = 4
ioctl(10, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
write(2, "You have running jobs\n", 22) = 22
rt_sigprocmask(SIG_BLOCK, [CHLD RTMIN], [RTMIN], 8) = 0
rt_sigprocmask(SIG_SETMASK, [RTMIN], [CHLD RTMIN], 8) = 0
ioctl(10, TIOCGWINSZ, {ws_row=55, ws_col=102, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(10, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost -isig -icanon -echo ...}) = 0
read(0, "\n", 1)                        = 1
write(2, "\r\n", 2)                     = 2
ioctl(10, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD RTMIN], [RTMIN], 8) = 0
rt_sigprocmask(SIG_SETMASK, [RTMIN], [CHLD RTMIN], 8) = 0
ioctl(10, TIOCGWINSZ, {ws_row=55, ws_col=102, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(10, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost -isig -icanon -echo ...}) = 0
read(0, "\4", 1)                        = 1
write(2, "^D\r\n", 4)                   = 4
ioctl(10, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
kill(-2442, SIGHUP)                     = 0
--- SIGINT {si_signo=SIGINT, si_code=SI_KERNEL} ---
rt_sigreturn({mask=[RTMIN]})            = 0
nanosleep({tv_sec=1, tv_nsec=0}, 0x7ff000fe60) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD RTMIN], [RTMIN], 8) = 0
rt_sigprocmask(SIG_SETMASK, [RTMIN], [CHLD RTMIN], 8) = 0
ioctl(10, TCGETS, {B38400 opost isig icanon echo ...}) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD RTMIN], [RTMIN], 8) = 0
madvise(0x7ec8048000, 4096, MADV_DONTNEED) = 0
madvise(0x7ec8024000, 4096, MADV_DONTNEED) = 0
fcntl(3, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(4, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(5, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(6, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(7, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(8, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(9, F_GETFD)                       = -1 EBADF (Bad file descriptor)
fcntl(10, F_GETFD)                      = 0x1 (flags FD_CLOEXEC)
close(10)                               = 0
fcntl(11, F_GETFD)                      = -1 EBADF (Bad file descriptor)
fcntl(31, F_GETFD)                      = -1 EBADF (Bad file descriptor)
close(2)                                = 0
close(1)                                = 0
close(0)                                = 0
mprotect(0x7ec8b48000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x7ec8b48000, 4096, PROT_READ) = 0
mprotect(0x7ec8b48000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x7ec8b48000, 4096, PROT_READ) = 0
munmap(0x7ec8b48000, 4096)              = 0
exit_group(0)                           = ?
+++ exited with 0 +++

标签: shelladb

解决方案


推荐阅读