Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This is my template to fork a deamon process in *nix */
- /* <[email protected]> */
- static void fork_daemon(void) {
- pid_t pid = fork();
- if(pid < 0) {
- fprintf(stderr, "Fork daemon failed\n");
- exit(EXIT_FAILURE);
- } else if(pid > 0) {
- // Success. The parent leaves here
- exit(EXIT_SUCCESS);
- }
- /* Fork off for the second time */
- /* This is needed to detach the deamon from a terminal */
- pid = fork();
- if(pid < 0) {
- fprintf(stderr, "Fork daemon failed (step two)\n");
- exit(EXIT_FAILURE);
- } else if(pid > 0) {
- // Success. The parent again leaves here
- exit(EXIT_SUCCESS);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment