이 상태에서 wait과 waitpid 차이가 있나요?

익명 사용자의 이미지

int pid = fork();
	if (pid == 0)
	{
		cout << "CHILD" << endl;
		exit(0);
	}
 
	int status;
 
	waitpid(pid, &status, 0);
	wait(&status);
 
	cout << "PARENTS" << endl;
	cout << WIFEXITED(status) << ", " << WEXITSTATUS(status) << endl;

위 코드에서 wait 과 waitpid 차이점이 있나요?

waitpid 옵션에 0을 넣었으니 wait과 별반 다르지 않는 것으로 알고있는데

현재 진행중인 프로젝트에서 왜 차이가 날까요...
waitpid으로 해야지 잘 작동하는데...

자식 한개에 waitpid 옵션도 0이면 wait과 waitpid 차이 없지 않나요?

twinwings의 이미지

man 2 wait

부모 프로세스인 경우 저 부분이 호출될 것인데, 그 때 (fork 성공시) pid 값는 -1이 아닙니다.

wait() and waitpid() 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);

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 behavior is modifiable via the options argument, as described below.