< prev index next >
src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c
Print this page
@@ -26,10 +26,11 @@
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <elf.h>
+#include <dirent.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <sys/uio.h>
#include "libproc_impl.h"
@@ -372,11 +373,11 @@
.get_lwp_regs= process_get_lwp_regs
};
// 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;
if ( (ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle))) == NULL) {
snprintf(err_buf, err_buf_len, "can't allocate memory for ps_prochandle");
@@ -399,11 +400,36 @@
// as the symbols in the pthread library will be used to figure out
// the list of threads within the same process.
read_lib_info(ph);
// read thread info
+ if (is_in_container) {
+ /*
+ * If the process is running in the container, SA scans all tasks in
+ * /proc/<PID>/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;
while (thr) {
// don't attach to the main thread again
< prev index next >