diff -r d02da43d8b98 -r af61810ccd5b src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c --- a/src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c Fri Jun 15 14:58:04 2018 +0200 +++ b/src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c Wed Aug 29 09:38:20 2018 +0200 @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -375,7 +376,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; @@ -402,7 +403,32 @@ read_lib_info(ph); // read thread info - read_thread_info(ph, add_new_thread); + if (is_in_container) { + /* + * If the process is running in the container, SA scans all tasks in + * /proc//task to read all threads info. + */ + 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;