I intercepted pthread_create
call to capture the relations among all the threads. But I found that some threads' creation were not recorded with only intercepting pthread_create
. I also tried to intercept posix_spawn
posix_spawnp
and clone
call. But there are still some threads that I don't know who create them running in my experiment. So are there any other ways to create threads on linux?
More specifically,
I used LD_PRELOAD to intercept pthread_create
call, the code fragment is shown below:
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg){
static void *handle = NULL;
static P_CREATE old_create=NULL;
if( !handle )
{
handle = dlopen("libpthread.so.0", RTLD_LAZY);
old_create = (P_CREATE)dlsym(handle, "pthread_create");
}
pthread_t tmp=pthread_self();
//print pthread_t pid
int result=old_create(thread,attr,start_routine,(void *)temp);
//print thread pid
return result;
}
In this way, I captured all the thread creation process. The same goes for clone
. But actually clone
was not called by the application. Sometimes, I got a parent-child threads pair which the parent thread is not printed before. So I don't know whether there are other ways to create this parent thread.
More more specifically, the upper application is a Mapreduce job on JVM1.7. I want to observe all the threads and processes and their relation
Thank you.