http://stackoverflow.com/questions/6583158/finding-open-file-descriptors-for-a-process-linux-c-code might feel less hacky? Although what you wrote totally works. Up to you.