Multithreading, Multiprocessing with STOP and Continuation of Signals

I am working on a project where I need to get my own Java application stack. I can achieve this in part. thanks to ptrace / multiprocessing and signals.

on Linux, a normal Java application has a minimum of 14 threads. Of these 14, I am only interested in the main thread, from which I should get my own stack. Given this goal, I started a separate process using fork (), which is tracking my own stack of the main thread. In short, I have 2 separate processes: one is controlled and the other, which monitors using ptrace and signal processing.

in the process of monitoring:

1) pull the main thread from another thread from the process.

2) ptrace_attach main_ID

3) ptrace_cont main_ID

continuous cycle begins

{

4) kill (main_ID, SIGSTOP),

5) the state of the nano and control status from the / proc / [pid] / stat directory

6) ptrace_peekdata for stack reading and navigation

7) ptrace_cont main_ID

8) the state of the nano and control status from the / proc / [pid] / stat directory

}

9) ptrace_detach main_ID

it perfectly gives information about the regular stack continuously. but sometimes I run into one problem.

Problem:

when I send kill (main_ID, SIGSTOP) to the main thread, other threads from the process go to the end or stop (T) state and all the blocks of the process. this is not sequence behavior, but the whole process is performed correctly. I could not understand this behavior, as I am only signaling the main thread, why are other threads affected by this? Can someone help me in analyzing the problem?

CONT STOP , .

,

+3
1

, Linux, tkill (2) tgkill (2) kill (2). FreeBSD SYS_thr_kill2. tkill (2):

tgkill() sig ​​ tgid. ( , kill (2) (.. ) , .)

tkill (2) , / .

, waitpid (2) ( ), , SIGSTOP /proc/ [pid]/stat. .

, , . Google PerfTools, , , CPU . , , , , .

0

Source: https://habr.com/ru/post/1762831/


All Articles