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)
#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)
...全文
相关推荐
linux的作业控制(job control)
Linux的作业控制(Job Control)是操作系统提供的一种功能,它允许用户在终端中管理多个任务,包括将任务放入后台运行、恢复前台运行以及监控任务状态。
Linux基础学习5
#### Job ControlJob Control 是Bash shell提供的一种机制,允许用户在同一终端窗口内同时管理多个进程。
linux bash手册(英文,version 4.2)
**Job Control** Job control是Bash的一个关键特性,允许用户在后台启动进程并管理它们。
基于X86工控机的嵌入式Linux移植
这通常是因为BusyBox的init进程默认开启了job control,而在某些环境中这并不适用。解决方法是重新编译BusyBox并禁用init的job control功能。2.
bash入门基础的介绍
在本文中,您将学会什么是 shell,Linux 上最常见的 shell 命令补齐、命令历史记录、别名、重定向和管道、改变提示符、进程控制(Job control),以及如何用户化配置您的 bash shell



