Created
January 18, 2010 18:42
-
-
Save Schabernack/280250 to your computer and use it in GitHub Desktop.
This file contains 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 <unistd.h> | |
#include <stdlib.h> | |
#include <signal.h> | |
void signalHandler(int sig){ | |
switch(sig){ | |
case SIGUSR1: | |
printf("\nSIGUSR1 erhalten \n"); | |
break; | |
case SIGTERM: | |
printf("\nSIGTERM erhalten. \n"); | |
exit(0); | |
break; | |
case SIGCHLD: | |
wait(); | |
} | |
} | |
int main(int argc, char *argv[]){ | |
int pid; | |
int status; | |
signal(SIGUSR1, signalHandler); | |
signal(SIGTERM, signalHandler); | |
signal(SIGCHLD, signalHandler); | |
if((pid=fork())>0){ | |
printf("Neuer Kindprozess erzeugt. ChildPID: %d \n", pid); | |
int i=0; | |
while(1){ | |
printf("\r %d", i); | |
fflush(stdout); | |
i++; | |
sleep(1); | |
} | |
} | |
else if(pid==0){ | |
printf("Ich bin der Childprozess. ParentPID: %d \n", getppid()); | |
char inp; | |
inp=getchar(); | |
switch(inp){ | |
case 'u': kill(getppid(),SIGUSR1); | |
case 't': kill(getppid(),SIGTERM); | |
case 's': execve("/bin/sh",NULL, NULL); | |
case 'e': exit(0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment