How to find out which process (stat: T) gdb is attached to?

When a process is bound by gdb, the stat of the process is "T", for example:

root      6507  0.0  0.0  67896   952 ?        Ss   12:01   0:00 /mytest
root      6508  0.0  0.0 156472  7120 ?        Sl   12:01   0:00 /mytest
root     26994  0.0  0.0  67896   956 ?        Ss   19:59   0:00 /mytest
root     26995  0.0  0.0 156460  7116 ?        Tl   19:59   0:00 /mytest
root     27833  0.0  0.0  97972 24564 pts/2    S+   20:00   0:00 gdb /mytest

Of the above, 26995 can be debugged. How can I find out 26995 is debugging or not? Or I can find out which process is related to gdb (27833)

pstree -p 27833 --- show gdb (27833)

Another question: How do I know the process (stat: T) associated with which gdb (PID)? In most cases, I am not a peony who debugs the process.

+5
source share
3 answers

The output Tin psmeans ptrace () d. So the process (26995) is traced by something. This is something most often either GDB, or strace.

, , GDB, strace, T, , .

GDB, (-) :

(gdb) info process
(gdb) info inferior

, T , , , ptrace()d.

, :

 grep '^TracerPid:' /proc/*/status | grep -v ':.0'
 /proc/7657/status:TracerPid:    31069

, 7657 31069. " ", " , ".

+7

/proc - Linux. /proc/{PID}/.

: (stat: T), GDB (PID)? , .

/proc/ {PID}/status, .

root     14616  0.0  0.0 36152  908 ?        Ss   Jun28   0:00 /mytest
root     14617  0.5  0.0 106192 7648 ?       Sl   Jun28 112:45 /mytest
tachyon   2683  0.0  0.0 36132 1008 ?        Ss   11:22   0:00 /mytest
tachyon   4276  0.0  0.0 76152 20728 pts/42  S+   11:22   0:00 gdb /mytest
tachyon   2684  0.0  0.0 106136 7140 ?       Tl   11:22   0:00 /mytest

host1-8 > cat/proc/2684/status

Name:   mytest
State:  T (tracing stop)
SleepAVG:       88%
Tgid:   2684
Pid:    2684
PPid:   2683
TracerPid:      4276
.......

, , 2684 4276.

+5

ps axf.

 1357 ?        Ss     0:00 /usr/sbin/sshd
 1935 ?        Ss     0:00  \_ sshd: root@pts/0
 1994 pts/0    Ss     0:00      \_ -bash
 2237 pts/0    T      0:00          \_ gdb /bin/ls
 2242 pts/0    T      0:00          |   \_ /bin/ls
 2243 pts/0    R+     0:00          \_ ps axf

2242 gdb 2237.

0

All Articles