--- old/src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c 2018-06-28 21:55:39.633338687 +0900 +++ new/src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c 2018-06-28 21:55:39.436343342 +0900 @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -374,7 +375,7 @@ // attach to the process. One and only one exposed stuff JNIEXPORT struct ps_prochandle* JNICALL -Pgrab(pid_t pid, char* err_buf, size_t err_buf_len) { +Pgrab(pid_t pid, char* err_buf, size_t err_buf_len, bool is_in_container) { struct ps_prochandle* ph = NULL; thread_info* thr = NULL; @@ -401,7 +402,28 @@ read_lib_info(ph); // read thread info - read_thread_info(ph, add_new_thread); + if (is_in_container) { + char taskpath[PATH_MAX]; + DIR *dirp; + struct dirent *entry; + + snprintf(taskpath, PATH_MAX, "/proc/%d/task", ph->pid); + dirp = opendir(taskpath); + int lwp_id; + while ((entry = readdir(dirp)) != NULL) { + if (*entry->d_name == '.') { + continue; + } + lwp_id = atoi(entry->d_name); + if (lwp_id == ph->pid) { + continue; + } + add_new_thread(ph, -1, lwp_id); + } + closedir(dirp); + } else { + read_thread_info(ph, add_new_thread); + } // attach to the threads thr = ph->threads;