grep doesn't run programs at all, its a pattern matching thing, you can essentially regex the stout of a program no the command line.
The program 'ls' on the command line lists programs running under the current user, you can do ls -ax to get all programs running. 'grep' would allow you to filter for the program names you want to actually deal with.
You could only tell which programs were in which directories if you got the PIDs right away, when the program first started running, and kept track of that somehow. So after each program starts, records the new PID you got from the ls -ax grep program_name
Then you would know which programs were running where, etc.
Then you could match up teh PIDs and deal with them by PID.
If that made sense...