views:

23

answers:

0

Hello ALL,

I am working on a project, where i need to get native stack of the Java Application. i am able to achieve this partially. thanks to ptrace/multiprocessing and signals.

on Linux normal java application has minimum 14 number of threads. out of these 14 i am interested in only main thread of which i have to get native stack. considering this objective i have started a separate process using fork() which is Monitoring the native stack of the main thread. in short i have 2 separate process: one is being monitored and other which does monitoring using ptrace and signal handling.

steps in the monitoring process:

1) get main thread-id out of other 14 thread from the process.

2) ptrace_attach main_ID

3) ptrace_cont main_ID

continuous loop starts

{

4) kill(main_ID, SIGSTOP),

5) nanosleep and check status from the /proc/[pid]/stat dir

6) ptrace_peekdata to read stack and navigate

7) ptrace_cont main_ID

8) nanosleep and check status from the /proc/[pid]/stat dir

}

9) ptrace_detach main_ID

this perfectly gives the native stack information continuously. but sometime i face one issue.

The issue:

when i send kill(main_ID, SIGSTOP) to main thread, other threads from the process get in finished or stoped state (T) and the entire process blocks. this is not the consistence behavior and entire process executes correctly. i could not understand this behavior as i am only signaling main thread, why other threads are affected of it? Could someone help me in analyzing the problem?

i also tried doing CONT and STOP signals on all the Threads of the process, but the issue still occurs sometimes.

Thanks, Sandeep