Created
July 5, 2014 17:21
-
-
Save sunny1304/b4ce48783d6a6ec80f78 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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