std::process::Child PID type compatibility

I recently needed to write some code that directly invokes libc::wait4, so that it can retrieve the rusage of the child process in addition to the exit status. libc::wait4 expects a libc::pid_t, a type alias for i32. However, Child::id() returns a u32. As a result, I end up having to use an as cast.

This seems like it ought to be fixable through type improvements. What change would it take to call libc::wait4 without a cast? Should Child have a method that returns a type compatible with OS PIDs? (Could we make that method portable, if possible?)

(Obviously we can’t change the type of the existing Child::id() method, but we could potentially add a new method that returns the correct type.)

Note that the unix implementation already stores the real pid_t and its id() uses as u32.

1 Like

Right, but I don’t see any way to get the underlying pid_t. That might not be possible in a portable way (though no platform seems to actually want a u32), but if that’s not possible, then perhaps with an associated type or an extension.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.