Skip to content

Instantly share code, notes, and snippets.

@sunny1304
Created July 5, 2014 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunny1304/b4ce48783d6a6ec80f78 to your computer and use it in GitHub Desktop.
Save sunny1304/b4ce48783d6a6ec80f78 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char* argv[])
{
pid_t pid, sid;
int status;
pid = fork();
if (pid < 0)
exit(EXIT_SUCCESS);
if (pid > 0)
exit(EXIT_SUCCESS);
umask(0);
sid = setsid();
if (sid<0)
exit(EXIT_FAILURE);
if (chdir("/") < 0)
exit(EXIT_FAILURE);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
while(true)
{
sleep(30);
status = system("service mysql stop");
if (status < 0)
{
system("service mysql start");
}
}
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment