'waitpid()'에 해당되는 글 2건

  1. 2010.01.11 fork-exec 종료시 리턴값
  2. 2009.11.20 좀비 프로세스 생성하기(!)
Linux2010. 1. 11. 09:42
fork-exec로 실행한 프로그램의 리턴값을 받는 방법이다.
예를 들어 mount를 쉘에서 실행하고 그 결과값을 받고 싶을때 사용한다.

#include <sys/types.h>
#include <sys/wait.h>

WEXITSTATUS
(status)
    returns the exit status of the child. This consists of the least significant 16-8 bits of the status argument that the child specified in a call to exit() or _exit() or as the argument for a return statement in main(). This macro should only be employed if WIFEXITED returned true.

[링크 : http://linux.die.net/man/2/waitpid]

[링크 : http://www.joinc.co.kr/modules/moniwiki/wiki.php/man/2/waitpid]
Posted by 구차니
Linux2009. 11. 20. 16:23
마지막으로 소스를 대충 보면, wait()를 하는 부분이 없네요. TestA가 daemon 형태로 re-parent한다면 상관없겠지만, 그렇지 않다면 아마 zombie 프로세스가 될 듯 합니다. zombie를 막으려면 daemon 형태로 만들거나, wait()로 child process의 return을 받아야 합니다. 그리고 이 때, SIGCHLD를 비롯, signal 처리를 하려면 pthread_sigmask() 등을 써서, signal을 원하지 않은 thread에서는 해당 시그널이 발생하지 않도록 block시켜야 합니다.

[링크 : http://kldp.org/node/103568]

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 terminated the child remains in a "zombie" state (see NOTES below).

[링크 : http://linux.die.net/man/2/waitpid]

프로세스 생성하고 parent에서 waitpid 하지 않으면 좀비가 생성된다.
ps 치면 Zombie 들이 우글우글 -ㅁ-
Posted by 구차니