socay2 发表于 2013-12-15 19:26

linux wait 等待进程状态改变,这里的状态包含哪些?

DESCRIPTION
       Allofthesesystemcallsare 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;orthechildwas
       resumedbya 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是要等到子进程结束了才解除阻塞呢?

井蛙夏虫 发表于 2013-12-15 21:46

回复 1# socay2
文档继续向下看

   

socay2 发表于 2013-12-15 22:52

回复 2# 井蛙夏虫
往下也没有解释呀!

   

井蛙夏虫 发表于 2013-12-16 01:11

回复 3# socay2
http://pubs.opengroup.org/onlinepubs/009695399/functions/wait.html

   

socay2 发表于 2013-12-16 15:48

回复 4# 井蛙夏虫

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

MMMIX 发表于 2013-12-16 16:03

socay2 发表于 2013-12-15 19:26 static/image/common/back.gif
可是通过kill 发送 SIGCONT 信号给子进程时,wait还是处于阻塞状态!


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

井蛙夏虫 发表于 2013-12-16 20:38

本帖最后由 井蛙夏虫 于 2013-12-16 20:42 编辑

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

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

       WNOHANG   return immediately if no child has exited.

       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.

       WCONTINUED (since Linux 2.6.10)
                   also return if a stopped child has been resumed by delivery of SIGCONT.

socay2 发表于 2013-12-16 22:47

MMMIX 发表于 2013-12-16 16:03 static/image/common/back.gif
在这之前子进程是处于 stop 状态么?发送完 SIGCONT 之后,子进程恢复运行了么?

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

socay2 发表于 2013-12-16 22:59

回复 7# 井蛙夏虫
我的系统是ubuntu 12.04,在man手册中的描述就如标题所述。
你的系统解释确实是进程 terminated , 不是进程状态 changed
可能是glibc库版本不一样吧

   

MMMIX 发表于 2013-12-17 09:51

socay2 发表于 2013-12-16 22:47 static/image/common/back.gif
在子进程中通过调用pause(),是否达到stop效果了呢?
不行。pause() 会让调用它的进程 sleep,而不是 stop。查看进程的状态可以使用 ps(1)。
页: [1] 2
查看完整版本: linux wait 等待进程状态改变,这里的状态包含哪些?