< prev index next >

src/jdk.hotspot.agent/linux/native/libsaproc/ps_proc.c

Print this page




 266     // We haven't found the line beginning with 'State:'.
 267     // Assuming the thread exists.
 268     print_error("Could not find the 'State:' string in the /proc/%d/status file\n", pid);
 269   }
 270   fclose (fp);
 271   return false;
 272 }
 273 
 274 // attach to a process/thread specified by "pid"
 275 static attach_state_t ptrace_attach(pid_t pid, char* err_buf, size_t err_buf_len) {
 276   errno = 0;
 277   if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
 278     if (errno == EPERM || errno == ESRCH) {
 279       // Check if the process/thread is exiting or is a zombie
 280       if (process_doesnt_exist(pid)) {
 281         print_debug("Thread with pid %d does not exist\n", pid);
 282         return ATTACH_THREAD_DEAD;
 283       }
 284     }
 285     char buf[200];
 286     char* msg = strerror_r(errno, buf, sizeof(buf));
 287     snprintf(err_buf, err_buf_len, "ptrace(PTRACE_ATTACH, ..) failed for %d: %s", pid, msg);
 288     print_error("%s\n", err_buf);

 289     return ATTACH_FAIL;
 290   } else {
 291     attach_state_t wait_ret = ptrace_waitpid(pid);
 292     if (wait_ret == ATTACH_THREAD_DEAD) {
 293       print_debug("Thread with pid %d does not exist\n", pid);
 294     }
 295     return wait_ret;
 296   }
 297 }
 298 
 299 // -------------------------------------------------------
 300 // functions for obtaining library information
 301 // -------------------------------------------------------
 302 
 303 /*
 304  * splits a string _str_ into substrings with delimiter _delim_ by replacing old * delimiters with _new_delim_ (ideally, '\0'). the address of each substring
 305  * is stored in array _ptrs_ as the return value. the maximum capacity of _ptrs_ * array is specified by parameter _n_.
 306  * RETURN VALUE: total number of substrings (always <= _n_)
 307  * NOTE: string _str_ is modified if _delim_!=_new_delim_
 308  */




 266     // We haven't found the line beginning with 'State:'.
 267     // Assuming the thread exists.
 268     print_error("Could not find the 'State:' string in the /proc/%d/status file\n", pid);
 269   }
 270   fclose (fp);
 271   return false;
 272 }
 273 
 274 // attach to a process/thread specified by "pid"
 275 static attach_state_t ptrace_attach(pid_t pid, char* err_buf, size_t err_buf_len) {
 276   errno = 0;
 277   if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
 278     if (errno == EPERM || errno == ESRCH) {
 279       // Check if the process/thread is exiting or is a zombie
 280       if (process_doesnt_exist(pid)) {
 281         print_debug("Thread with pid %d does not exist\n", pid);
 282         return ATTACH_THREAD_DEAD;
 283       }
 284     }
 285     char buf[200];
 286     if (strerror_r(errno, buf, sizeof(buf) == 0)) {
 287       snprintf(err_buf, err_buf_len, "ptrace(PTRACE_ATTACH, ..) failed for %d: %s", pid, buf);
 288       print_error("%s\n", err_buf);
 289     }
 290     return ATTACH_FAIL;
 291   } else {
 292     attach_state_t wait_ret = ptrace_waitpid(pid);
 293     if (wait_ret == ATTACH_THREAD_DEAD) {
 294       print_debug("Thread with pid %d does not exist\n", pid);
 295     }
 296     return wait_ret;
 297   }
 298 }
 299 
 300 // -------------------------------------------------------
 301 // functions for obtaining library information
 302 // -------------------------------------------------------
 303 
 304 /*
 305  * splits a string _str_ into substrings with delimiter _delim_ by replacing old * delimiters with _new_delim_ (ideally, '\0'). the address of each substring
 306  * is stored in array _ptrs_ as the return value. the maximum capacity of _ptrs_ * array is specified by parameter _n_.
 307  * RETURN VALUE: total number of substrings (always <= _n_)
 308  * NOTE: string _str_ is modified if _delim_!=_new_delim_
 309  */


< prev index next >