Linux job control

forlove89 2014-12-22 08:26:07
#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)
...全文
170 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

18,772

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧