Linux job control
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char **argv)
{
pid_t pid;
int ch;
int status;
if ((pid = fork()) < 0) {
printf("fork error");
_exit(1);
} else if (pid == 0) {
printf("come into child\n");
while((ch = getchar()) != EOF) {
printf("child get char: %d\n", ch);
}
_exit(0);
}
printf("parent waitting [%d]\n", pid);
do {
if(-1 == waitpid(pid, &status, WUNTRACED | WCONTINUED)) {
printf("wait failure");
_exit(1);
}
if (WIFEXITED(status)) {
printf("exited, status=%d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("killed by signal %d\n", WTERMSIG(status));
} else if (WIFSTOPPED(status)) {
printf("stopped by signal %d\n", WSTOPSIG(status));
} else if (WIFCONTINUED(status)) {
printf("continued\n");
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
printf("parent exit...\n");
exit(0);
}
在linux后台执行 (./jobcontrol &), 为什么父进程和子进程都处于T状态(TASK_STOPPED)