Sorry for the vague question, but I've just written some php code that executes itself as CLI, and I'm pretty sure it's misbehaving. When I run "top" on the command line it's showing very little resources given to any individual process, but between 40-98% to iowait time (%wa). I usually have about .7% distributed between %us and %sy, with the remaining resources going to idle processes (somewhere between 20-50% usually).

This server is executing MySQL queries in, easily, 300x the time it takes other servers to run the same query, and it even takes what seems like forever to log on via SSH... so despite there being some idle cpu time left over, it seems clear that something very bad is happening. Whatever scripts are running, are updating my MySQL database, but it seems to be exponentially slower then when they started. 

I need some ideas to serve as launch points for me to diagnose what's going on.

Some things that I would like to know are:

1. How I can confirm how many scripts are actually running
2. Is there anyway to confirm that these scripts are actually shutting down when they are through, and not just "hanging around" taking up CPU time and memory?
3. What kind of bottlenecks should I be checking to make sure I don't create too many instances of this script so this doesn't happen again.

I realize this is probably a huge question, but I'm more then willing to follow any links provided and read up on this... I just need to know where to start looking.