Details
Description
We have have a multi-threaded program with multiple connections to the database. While this program is running, we often get a single child process (pid) that just hangs. This particular child process consumes 100% of any given CPU. We are trying to troubleshoot this and trying to determine which child pid maps to the SHOW PROCESSLIST Id.
With that in mind, we would like to know if there is a way to map a linux child pid that's associated with the linux parent pid (ppid) of the mysqld process to the Id shown in the output of SHOW PROCESSLIST.
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
Following is a suggestion, provided by one of our senior developers, which could be used to accomplish this feature request.
There is a code suggestion, made by Chrisian Hammers, 2008, back for MySQL 5.0.x,
documented in MySQL feature request:
http://bugs.mysql.com/bug.php?id=33799.
However, I have a correction for the 'FIXME' line:
The PID &/or Thread IDs are easily available, but only to the parent process and child thread or process.
A) From the parent process perspective, the child PID or thread_id is only made available during thread creation:
The return code from fork(), is the PID of the child process. (Doc here http://pubs.opengroup.org/onlinepubs/007908799/xsh/fork.html)
The first parameter from the POSIX function pthread_create(). (Doc here http://pubs.opengroup.org/onlinepubs/007908799/xsh/pthread_create.html)
The sixth parameter from the Solaris function thr_create(). (Doc here http://docs.oracle.com/cd/E19253-01/816-5137/sthreads-69878/index.html)
B) From within the child Thread/Lwp (via pthread_create()), the thread_id is made available through:
The return code from POSIX function, gettid().
EX:
#include <sys/types.h> pid_t gettid(void);The return code from syscall(SYS_gettid), where SYS_gettid is an enum.
EX:
#include <sys/types.h> #include <sys/syscall.h> #define gettid() syscall(SYS_gettid);The return code from Solaris function, thr_self().
EX:
#include <thread.h> thread_t thr_self();C) From within the child process (via fork()), the PID is made available, at anytime through:
The return code from getpid().
EX:
#include <unistd.h> pid_t getpid();