I was wondering if we can use the system call
waitpid()
to wait a pid of a grandchildren
waitpid()
is POSIX.
The wait() and waitpid() functions shall obtain status information (see Status Information) pertaining to one of the caller's child processes.
So the answer to your question is "No", at least from the standard's perspective.
This does not necessarily have to keep implementations from providing extensions to the standard.
From POSIX as well:
Nothing in this volume of POSIX.1-2008 prevents an implementation from providing extensions that permit a process to get status from a grandchild or any other process, but a process that does not use such extensions must be guaranteed to see status from only its direct children.