2
votes

When the waitpid() function is implemented in the following way,what does it return when the child is stopped due to SIGTSTP signal? and why?

waitpid(pid,&status,WUNTRACED);
where pid is process id of any process and status is of type int.

Does it also suspends the calling process till it not found any stopped or terminated child or it won't affect the ongoing process?

1

1 Answers

2
votes

It returns the process ID of the stopped child process.

POSIX states that

WUNTRACED

The status of any child processes specified by pid that are stopped, and whose status has not yet been reported since they stopped, shall also be reported to the requesting process.

and

If wait() or waitpid() returns because the status of a child process is available, these functions shall return a value equal to the process ID of the child process for which status is reported. (...)

here.

This return value is, of course, more interesting if there are several child processes and pid in the call is 0 or less, so that you don't know the PID of the reported child process in advance, but you get it either way.