For debugging purposes, it’s sometimes necessary to debug multiples PIDs at a same time with strace tool.
I will take a simple example: PHP-FPM. PHP-FPM is creating several processes depending on its needs, and if you want to perform debugging on it, you can’t easily know what each process is doing. In order to get the results of all the PIDs created for php-fpm, you can use the following command:
strace-tt-T$(pidof'php-fpm: pool www'|sed's/\([0-9]*\)/\-p \1/g')
In this command, you can see:
“-tt” option: displays a more precise time on each line (with microseconds)
“-T” option: show the time spent in the call
“pidof ‘php-fpm: pool www’“: retrieves all the PIDs of processes called “php-fpm: pool www” (you can adapt it depending on your process name)
Thanks to this command, you will get the strace result for all your PHP-FPM processes (you can filter them later thanks to PID displayed at the beginning of each line).
When you are getting some errors from PHP-FPM like “signal 11 (core dumped)” in your logs, you can need to generate some core dumps to understand what’s happening.
You first need to install some packages to allow you generating dumps:
apt-get install gdb php5-dbg
System core updates
You will then need to update some sysctl parameters. Those commands will request root access to be executed.
Obviously, you can change the directory in which one you want to put the core dumps depending on your configuration (here /opt/core/ is used):
%ccore file size soft resource limit of crashing process(since Linux2.6.24)
Update PHP-FPM config
Once system configuration performed, you will need to update php-fpm configuration as well.
Edit file /etc/php5/fpm/php-fpm.conf (or specific pool configuration file under pool.d directory) and uncomment following line:
Once done, restart php5-fpm service:
Your core dumps will now be created in the folder you indicated at the beginning as soon as a new core dump will be generated.
Check your core dumps
Check your PHP-FPM logs, and if you see something like:
[01-Jan-201505:30:15]WARNING:[pool www]child547934exited on signal11(SIGSEGV-core dumped)after410.674135seconds from start
Go to the folder you chose for storing core dumps and you will see your core dump files: