Here is a simple little replacement for system() that does close file descriptors. The main issue with it is though, it ends up picking an arbitrary number of fds to close. I picked closing 0 to 99.
Aaron int s_system(const char *string) { pid_t pid; int x; pid = fork() if(pid == -1) { return -1; } if(pid > 0) { int status; wait(&status); return(status); } for(x = 0; x < 100; x++) { close(x); } execlp("/bin/sh", "-c", string); }