rendered paste body#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t pid = fork();
printf("Mit If:\t\t");
// Fehlerbehandlung für Fork
if (pid < 0) { printf("Error, wrong PID\n"); }
// Im Vaterprozess:
else if (pid > 0) { printf("[PID: %i] father\n", getpid()); }
// Im Kindprozess:
else { printf("[PID: %i] child\n", getpid()); }
printf("Mit Switch:\t");
switch (pid)
{
case 0: printf("[PID: %i] child\n", getpid());
break;
case -1: printf("Error, wrong PID\n");
break;
default: printf("[PID: %i] father\n", getpid());
break;
}
return 0;
}