Skip to content

Instantly share code, notes, and snippets.

@45deg
Created October 6, 2015 15:35
Show Gist options
  • Save 45deg/0dd51fbc28792395775e to your computer and use it in GitHub Desktop.
Save 45deg/0dd51fbc28792395775e to your computer and use it in GitHub Desktop.
#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;
}
@45deg
Copy link
Author

45deg commented Aug 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment