PHP Code:
#include <signal.h>
#include <st***.h>
#include <stdlib.h>
/***
* _ _
* (_) (_)
* __ ____ _ _ _____ ___ ___ ___ ___ _ __ ___
* \ \/ / _` | |/ _ \ \ / / |/ _ \ / __/ _ \| '_ ` _ \
* > < (_| | | (_) \ V /| | (_) | (_| (_) | | | | | |
* /_/\_\__, |_|\___/ \_/ |_|\___(_)___\___/|_| |_| |_|
* __/ |
* |___/
*
* Alter SIGINT signal from shell. It will ask you if you are sure
* to kill the process.
*
* v 1.0
*
*
*/
void xflush ( FILE* stream ) {
int temp;
temp = fgetc ( stream );
for (; temp != '\n' ;temp = fgetc ( stream )){}
}
void ask ( int signal) {
char * stringa;
stringa = (char *) malloc (20);
if ( stringa == NULL) { fprintf(stderr,"Impossibile completarel'operazione\n");exit(-2);}
fprintf ( stdout, "\nDo you want to quit me? y\\n\n");
fscanf( stdin, "%19s", stringa);
xflush (stdin);
for (;(strcmp(stringa,"y") != 0) && (strcmp(stringa,"n") != 0);){
fprintf ( stdout, "Wrong Answer \n");
fscanf( stdin, "%19s", stringa);
xflush (stdin);
}
if ( strcmp(stringa,"y") == 0){
fprintf(stdout,"Signal processed. Goodbye friend. I'm dying ...\n");
kill (getpid(),SIGKILL);
fprintf(stderr, "You can't kill me!\n");
}
}
int main ( void ) {
struct sigaction sigint_action;
sigint_action.sa_handler = ask;
sigint_action.sa_flags = 0;
sigaction ( SIGINT, &sigint_action, NULL);
fprintf(stdout,"Press ctrl-c if you want to kill me....\n");
for(;-1;){
pause ();
fprintf(stdout,"Signal processed but i'm still here. Thank you. Press ctrl-c if you want to kill me\n");
}
return 0;
}