These are from the documentation on waitpid() https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html
About the pid parameter
If pid is greater than 0, it specifies the process ID of a single child process for which status is requested.
About the return value
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.
From this, I expect that if I pass a positive int (pid) I should get the same number as the return value.
I am observing that in some cases when I call waitpid() with a positive integer representing a pid with no other option parameters (the third paraeter is 0), the call returns another integer which is not equal to the pid passed in (although it is close in value).
So, when does waitpid() call return a value different from the the pid (>0) passed?
Edit 1:
The call looks like this: waitpid(pid, &status, 0)
pid is an int (>0) status is an int
In some of the runs the value of PID passed and returned are different: (In the below lines a!=b where a is the return value, b is the PID passed to waitpid() )
2019-11-21, 09:38:11.573007 [info] - WAITPID CALL: 16881!= 16890
2019-11-21, 09:38:11.573007 [info] - WAITPID CALL: 16881!= 16890
2019-11-21, 09:39:11.149065 [info] - WAITPID CALL: 17087!= 17096
2019-11-21, 09:41:11.570292 [info] - WAITPID CALL: 17433!= 17442
2019-11-21, 09:43:11.373236 [info] - WAITPID CALL: 17761!= 17770
This behavior is not consistent but happens once in a few runs.