/*include/linux/sched.h*/struct task_struct {
volatilelong state; /* -1 unrunnable, 0 runnable, >0 stopped */void *stack;
atomic_t usage;
unsignedint flags; /* per process flags, defined below */int prio, static_prio, normal_prio;
unsignedint rt_priority;
struct list_head tasks;
struct mm_struct *mm, *active_mm;
/* task state */int exit_state;
int exit_code, exit_signal;
int pdeath_signal; /* The signal sent when the parent dies *//* Revert to default priority/policy when forking */unsigned sched_reset_on_fork:1;
unsigned sched_contributes_to_load:1;
unsignedlong atomic_flags; /* Flags needing atomic access. */
pid_t pid;
pid_t tgid;
/*
* children/sibling forms the list of my natural children
*/struct list_head children; /* list of my children */struct list_head sibling; /* linkage in my parent's children list */struct task_struct *group_leader; /* threadgroup leader *//* PID/PID hash table linkage. */struct pid_link pids[PIDTYPE_MAX];
struct list_head thread_group;
struct list_head thread_node;
struct completion *vfork_done; /* for vfork() *//* CPU-specific state of this task */struct thread_struct thread;
/* filesystem information */struct fs_struct *fs;
/* open file information */struct files_struct *files;
/* signal handlers */struct signal_struct *signal;
}
int main(void)
{
pid = fork();
do {
wait_pid=waitpid(pid, &status, WUNTRACED | WCONTINUED);
if (wait_pid == -1) {
perror("cannot using waitpid function");
exit(1);
}
……
if(WIFSIGNALED(status))
printf("child process is killed by signal %d\n", WTERMSIG(status));
……
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
exit(0);
}