Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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