structfdtable __rcu *fdt; structfdtablefdtab; /* * written part on a separate cache line in SMP */ spinlock_t file_lock ____cacheline_aligned_in_smp; unsignedint next_fd; unsignedlong close_on_exec_init[1]; unsignedlong open_fds_init[1]; unsignedlong full_fds_bits_init[1];
intmain(void){ int status = 0; pid_t child_pid = fork();
if (child_pid == -1) { perror("can not fork process:"); } elseif (child_pid == 0) { printf("This is child process, my pid is %d\n", getpid()); while(1); } else { #if CLEAR_CHILD_PID printf("This is parent process, i get child pid is %d\n", child_pid);
if (waitpid(child_pid, &status, 0)) {
} if(WIFEXITED(status)) { printf("The child was terminated normally!"); printf("exit status = %d\n", WEXITSTATUS(status)); } if(WIFSIGNALED(status)) { printf("The child was terminated by signal %d\n", WTERMSIG(status)); #ifdef WCOREDUMP if(WCOREDUMP(status)) { printf("The child produced a core dump!\n"); } #endif } if(WIFSTOPPED(status)) { printf("The chiild process was stopped by delivery of a signal %d\n", WSTOPSIG(status)); } if(WIFCONTINUED(status)) { printf("The child process was resumed by delivery of SIGCONT\n"); } #else while(1); #endif }
if(child_pid == -1) { perror("can not fork process:"); } elseif(child_pid == 0) { printf("This is child process, my pid is %d\n", getpid()); printf("check parent pid...\n"); while(1) { printf("My parent pid is %d\n", getppid()); sleep(1); } } else { #if CLEAR_CHILD_PID printf("This is parent process, i get child pid is %d\n", child_pid); if(waitpid(child_pid, &status, 0)) {
} if(WIFEXITED(status)) { printf("The child was terminated normally!"); printf("exit status = %d\n", WEXITSTATUS(status)); } if(WIFSIGNALED(status)) { printf("The child was terminated by signal %d\n", WTERMSIG(status)); #ifdef WCOREDUMP if(WCOREDUMP(status)) { printf("The child produced a core dump!\n"); } #endif } if(WIFSTOPPED(status)) { printf("The chiild process was stopped by delivery of a signal %d\n", WSTOPSIG(status)); } if(WIFCONTINUED(status)) { printf("The child process was resumed by delivery of SIGCONT\n"); } #else while(1) { sleep(1); } #endif }
voidsig_handler(int num){ int status = 0; printf("get sig_handler = %d\n", num); if(waitpid(-1, &status, 0) == -1) { perror("wait signal failed!"); } if(WIFEXITED(status)) { printf("The child was terminated normally!"); printf("exit status = %d\n", WEXITSTATUS(status)); } if(WIFSIGNALED(status)) { printf("The child was terminated by signal %d\n", WTERMSIG(status)); #ifdef WCOREDUMP if(WCOREDUMP(status)) { printf("The child produced a core dump!\n"); } #endif } if(WIFSTOPPED(status)) { printf("The chiild process was stopped by delivery of a signal %d\n", WSTOPSIG(status)); } if(WIFCONTINUED(status)) { printf("The child process was resumed by delivery of SIGCONT\n"); } }
intmain(void){
if(prctl(PR_SET_CHILD_SUBREAPER, 1) < 0) { perror("can not to be a subreaper!"); return-1; }