Created
October 6, 2015 15:35
-
-
Save 45deg/0dd51fbc28792395775e to your computer and use it in GitHub Desktop.
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <syslog.h> | |
int main(int argc, char const* argv[]) | |
{ | |
int pid = 0; | |
int status; | |
char const* run_cmd = argv[1]; | |
openlog("heartbeat", LOG_CONS | LOG_PID, LOG_USER); | |
while(1) { | |
pid = fork(); | |
if(pid == -1) { | |
syslog(LOG_EMERG, "Fork failed."); | |
exit(EXIT_FAILURE); | |
} else if(pid == 0) { | |
// child | |
(void) chdir("/path/to/hoge"); | |
execlp("hoge", "hoge", | |
"arg0", "arg1" | |
NULL); | |
exit(-1); | |
} else { | |
// parent | |
wait(&status); | |
syslog(LOG_INFO, "Das kind ist tot."); | |
sleep(10); | |
} | |
} | |
closelog(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also: https://www.npmjs.com/package/forever