免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4013 | 回复: 14

[Linux] linux wait 等待进程状态改变,这里的状态包含哪些? [复制链接]

论坛徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
发表于 2013-12-15 19:26 |显示全部楼层
DESCRIPTION
       All  of  these  system  calls  are used to wait for state changes in a child of the calling process, and obtain information about the child
       whose state has changed. A state change is considered to be: the child terminated; the child was stopped by a signal;  or  the  child  was
       resumed  by  a signal
.  In the case of a terminated child, performing a wait allows the system to release the resources associated with the
       child; if a wait is not performed, then the terminated child remains in a "zombie" state (see NOTES below).
这是源自man wait的解释,这里解释说进程的终止、停止、和唤醒都叫做状态的改变。可是通过kill 发送 SIGCONT 信号给子进程时,wait还是处于阻塞状态! 请问是不是wait是要等到子进程结束了才解除阻塞呢?

论坛徽章:
4
白羊座
日期:2013-09-17 21:59:30技术图书徽章
日期:2013-10-12 22:16:03白羊座
日期:2013-10-14 11:01:40双子座
日期:2013-12-17 18:26:39
发表于 2013-12-15 21:46 |显示全部楼层
回复 1# socay2
文档继续向下看

   

论坛徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
发表于 2013-12-15 22:52 |显示全部楼层
回复 2# 井蛙夏虫
往下也没有解释呀!

   

论坛徽章:
4
白羊座
日期:2013-09-17 21:59:30技术图书徽章
日期:2013-10-12 22:16:03白羊座
日期:2013-10-14 11:01:40双子座
日期:2013-12-17 18:26:39
发表于 2013-12-16 01:11 |显示全部楼层

论坛徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
发表于 2013-12-16 15:48 |显示全部楼层
回复 4# 井蛙夏虫

谢谢!
这个解释和man手册描述的稍稍有一点不一样
   

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
发表于 2013-12-16 16:03 |显示全部楼层
socay2 发表于 2013-12-15 19:26
可是通过kill 发送 SIGCONT 信号给子进程时,wait还是处于阻塞状态!


在这之前子进程是处于 stop 状态么?发送完 SIGCONT 之后,子进程恢复运行了么?

论坛徽章:
4
白羊座
日期:2013-09-17 21:59:30技术图书徽章
日期:2013-10-12 22:16:03白羊座
日期:2013-10-14 11:01:40双子座
日期:2013-12-17 18:26:39
发表于 2013-12-16 20:38 |显示全部楼层
本帖最后由 井蛙夏虫 于 2013-12-16 20:42 编辑

回复 5# socay2
这个是posix标准文档。
我的系统上的man文档是有说的,不知道为什么你系统的没有。
  1. The wait() system call suspends execution of the calling process until one of its children terminates.  The call wait(&status) is equivalent to:

  2.            waitpid(-1, &status, 0);
复制代码
wait只能是子进程终止。如果要子进程继续和暂停都可以,要用waitpid
  1. The  waitpid()  system  call  suspends  execution  of the calling process until a child specified by pid argument has changed state.  By default, waitpid() waits only for terminated children, but this
  2.        behavior is modifiable via the options argument, as described below.
复制代码
  1. The value of options is an OR of zero or more of the following constants:

  2.        WNOHANG     return immediately if no child has exited.

  3.        WUNTRACED   also return if a child has stopped (but not traced via ptrace(2)).  Status for traced children which have stopped is provided even if this option is not specified.

  4.        WCONTINUED (since Linux 2.6.10)
  5.                    also return if a stopped child has been resumed by delivery of SIGCONT.
复制代码

论坛徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
发表于 2013-12-16 22:47 |显示全部楼层
MMMIX 发表于 2013-12-16 16:03
在这之前子进程是处于 stop 状态么?发送完 SIGCONT 之后,子进程恢复运行了么?


在子进程中通过调用pause(),是否达到stop效果了呢?

论坛徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
发表于 2013-12-16 22:59 |显示全部楼层
回复 7# 井蛙夏虫
我的系统是ubuntu 12.04,在man手册中的描述就如标题所述。
你的系统解释确实是进程 terminated , 不是进程状态 changed
可能是glibc库版本不一样吧

   

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
发表于 2013-12-17 09:51 |显示全部楼层
socay2 发表于 2013-12-16 22:47
在子进程中通过调用pause(),是否达到stop效果了呢?

不行。pause() 会让调用它的进程 sleep,而不是 stop。查看进程的状态可以使用 ps(1)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP