Vater- und Kindprozesse
-
Ok, hat sich erledigt. Waren mal wieder Tomaten auf den Augen. Bitte um Nachsicht.
#include <stdio.h> #include <unistd.h> #include <time.h> #include <sys/types.h> #include <stdlib.h> #include <signal.h> int main() { pid_t pid_1; pid_t pid_2; int i = 5; int n = 98; time_t timer; pid_1 = fork(); /*Sohnprozess*/ if(pid_1 == 0) { sleep(15); exit(0); /*Vaterprozess*/ } else if (pid_1 > 0) { pid_2 = fork(); if(pid_2 == 0) { while(1) { n+i; } } kill(pid_2, SIGKILL); printf("PID Vater : %d\n", (int) getppid()); printf("PID Sohn 1: %d\n", pid_1); printf("PID Sohn 2: %d\n", pid_2); printf("Zeit: %s\n", asctime(localtime(&timer))); system("ps -H"); exit(0); } return 0; }