#include #include #include #include //#include //#include #include #include #include void parent_terminate(int test) // Routine fuer SIGCLD { //cout << "Das Vater-Programm wurde gekillt!\n\n"; exit(0); } int main(int argc, char *argv[]) { int childpid; unsigned int wait_sec=atoi(argv[1]); char eingabe[100]; //signal(SIGCLD, SIG_IGN); signal(SIGCLD, parent_terminate); //printf("pid des Prozesses = %d, Parent-pid des Prozesses = %d\n\n",getpid(), getppid()); if ((childpid = fork()) == -1) { cerr << "Fehler Kann nicht geforkt werden!!!\n" << endl; exit(1); } else if (childpid == 0) { /* Kindprozess */ //printf("child Prozess mit dem PID = %d, und die parent-PID = %d\n", getpid(), getppid()); cin >> eingabe; cout << eingabe; exit(0); } else { /* Parent prozess */ sleep(wait_sec); //printf("parent Prozess mit dem PID = %d, und die geforkte child-PID = %d\n", getpid(), childpid); kill(childpid, SIGKILL); cout << ""; exit(0); } }