printf("Accepted connection from %s on port %d\n", inet_ntoa(client_address.sin_addr), client_address.sin_port);
pid_t parent_pid = getpid(); #ifdef PROC // PART2 TASK: Implement forking /* YOUR CODE HERE */ pid_t child_pid = fork(); if (child_pid != 0) { // Kill child process if parent dies int r = prctl(PR_SET_PDEATHSIG, SIGTERM);
/* YOUR CODE HERE */ dispatch(client_socket_number); // Exit with code 1 when there was an error, // or when the parent has been killed if (r == -1 || getppid() != parent_pid) { perror(0); exit(1); }
/* YOUR CODE HERE */ exit(EXIT_SUCCESS); } #else dispatch(client_socket_number); #endif }