I am attempted to create a script that show how much each process and subprocess of mysqld is using. You can see what I have done in my code.
#!/bin/bash
#fi
Calculating a processes memory usage is... complicated. I generally use a proc's RSS -- Resident Set Size -- the amount of memory a process is holding in memory, that isn't shared by other procs.
The following finds the process ID of the MySQL daemon, and uses ps
to output the RSS value with no header. Lastly it multiplies this by four to get the RSS size in KiB. (Default pagesize is 4 KiB.)
ps has tons of information -- have fun!
ps -o rss= -p `pidof mysqld` | awk '{print $1*4, "KiB"}'
7808 KiB