Created
July 25, 2012 20:43
-
-
Save christopherdeutsch/3178561 to your computer and use it in GitHub Desktop.
execnofd - run a program after closing file descriptors >2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* execnofd | |
| * | |
| * exec a program after closing all fd's > 2 | |
| * | |
| * Syntax: execnofd <command> <options> | |
| * | |
| * Example: execnofd ls -l /home | |
| * | |
| */ | |
| #include <stdio.h> | |
| #include <unistd.h> | |
| int main(int argc, char *argv[]) { | |
| int maxfd = sysconf(_SC_OPEN_MAX); | |
| for(int i = 3; i < maxfd; i++) { | |
| close(i); | |
| } | |
| execvp(argv[0], &argv[1]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment