Back to the original, unhijacked (grin) question:
There's a way to do this that's possibly simpler than your C code.
Open the
/proc directory, as you're doing. Concentrate on the process names by concentrating on numbers, as you're doing.
For process 2345, for example, look at 2345/exe, which is a symbolic link. It links to whatever is being executed, like
/bin/bash. That gives you the name of the program you're running. It's arguably easier to read a symbolic link than to parse text.
It's also fun to try the proof of concept on the command line, since
bash will use its own process number when you put $$ on the command line:
Um, since you're already concentrating on numbered processes, you can leave out the explicit check for "..".
Hope this helps.