Discover pid of Child using std::process:::Command


#1

Is there any way of discovering the process id (presumably not portably) for a Child generated by std::process::Command? I want to record the PID in a file (so later I can discover if it is still running and kill it).

I suppose as a workaround I could record the ID of the parent process, but then I need to listen for signals and kill the child and clean up. Not the end of the world, but definitely a nuisance… and it also prevents me from waiting on the child, so I’d be forced to use polling, which is both ugly and inefficient.


#2

Okay, I see how to do this, and feel silly for even asking.

https://doc.rust-lang.org/std/process/struct.Child.html#method.id

I searched for “pid” not even thinking that it might be called something different!