Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simplistic daemonize tool by /u/Craftkorb
- // $ gcc -o d daemonize.c
- #include <errno.h>
- #include <fcntl.h>
- #include <stdio.h>
- int main (int argc, char **argv) {
- if (argc < 2) {
- printf ("Usage: %s <Command ...>\n", argv[0]);
- return 1;
- }
- //
- if (fork () == 0) {
- close (fileno(stdout));
- close (fileno(stderr));
- close (fileno(stdin));
- open ("/dev/null", O_WRONLY | O_NONBLOCK);
- open ("/dev/null", O_RDONLY | O_NONBLOCK);
- open ("/dev/null", O_RDONLY | O_NONBLOCK);
- execvp (argv[1], argv + 1);
- perror ("Failed to execute");
- return errno;
- }
- //
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement