双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

Linux job control

forlove89 forlove89 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#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)
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
forlove89
Linux/Unix社区 18,828 成员 11,488 内容