设为首页 加入收藏

TOP

6进程原语:wait()和waitpid()函数(三)
2015-07-20 17:38:54 来源: 作者: 【 】 浏览:12
Tags:进程 wait waitpid 函数
CAgICAgICAgIGludCBzdGF0dXM7PC9wPgoKPHA+IDwvcD4KCjxwPiAgICAgICAgICBjcGlkID0gZm9yaygpOzwvcD4KCjxwPiAgICAgICAgICBpZiAoY3BpZCA9PSAtMSkgezwvcD4KCjxwPiAgICAgICAgICAgICAgCnBlcnJvcig="fork");

exit(EXIT_FAILURE);

}

if (cpid == 0) { /*Code executed by child */

printf("Child PID is%ld\n", (long) getpid());

if (argc == 1)

pause(); /* Wait for signals */

_exit(atoi(argv[1]));

} else { /*Code executed by parent */

do {

w = waitpid(cpid,&status, WUNTRACED | WCONTINUED);

if (w == -1) {

perror("waitpid");

exit(EXIT_FAILURE);

}

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 bysignal %d\n", WSTOPSIG(status));

} else if(WIFCONTINUED(status)) {

printf("continued\n");

}

} while (!WIFEXITED(status)&& !WIFSIGNALED(status));

exit(EXIT_SUCCESS);

}

}

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU-5031-Lines(DFS) 下一篇HDU 1565 方格取数(1) (状态压缩..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·利用python进行数据 (2025-12-25 20:49:22)
·如何使用 python 中 (2025-12-25 20:49:19)
·零基础如何学爬虫技 (2025-12-25 20:49:17)
·Java 并发工具类:提 (2025-12-25 20:25:44)
·Java面试技巧:如何 (2025-12-25 20:25:41)