Add support for waitid().

Resolves #985.