Skip to content

Instantly share code, notes, and snippets.

@Schabernack
Created January 18, 2010 18:42
Show Gist options
  • Save Schabernack/280250 to your computer and use it in GitHub Desktop.
Save Schabernack/280250 to your computer and use it in GitHub Desktop.
#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