On my linux machine there was a script which was accessing mysql withing a while(true) loop. It has caused my cpu usage to 99%-100%. But I couldn't find exactly what script was doing this. Following was the script code.
while (true) {
$con = mysql_connect("localhost","root","root");
mysql_select_db("test_db", $con);
$result = mysql_query("SELECT * FROM hs_hr_employee");
mysql_close($con);
}
I tried to identify the exact process through the top command. The result was as bellow.
Even though this shows mysqld is taking 100% pf CPU usage. this didn't showed me what was the exact script which was causing this issue.
Then I tried ps command to find out any hint on this.
ps -aux | grep mysqld
The output was as follows.
It also didn't gave any hint about this running php script. In this kind of scenario how we can troubleshoot exactly to identify the trouble making scripts and commands. Please help me on this.
Thanks in advance.
mysqld
is the process that's using the most CPU. With a command likeps aux --forest
(or, more prettily,pstree
), you can visualise processes in a tree structure, so you can easily see parentage.