Skip to content

Instantly share code, notes, and snippets.

@geekoff7
Created July 24, 2018 05:55
Show Gist options
  • Select an option

  • Save geekoff7/b498b62cfe8c279548feb29e829566c0 to your computer and use it in GitHub Desktop.

Select an option

Save geekoff7/b498b62cfe8c279548feb29e829566c0 to your computer and use it in GitHub Desktop.
signal handler function in c program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
volatile sig_atomic_t please_stop;
void handler_sigint()
{
please_stop = 1;
}
int main(int argc, char const *argv[])
{
printf("%d \n", getpid());
signal(SIGINT, handler_sigint);
while (please_stop == 0)
{
sleep(1);
write(1, ".", 1);
}
if (please_stop == 1)
{
write(1, "clean !!!", 10);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment