title: How to programmatically gain root privileges?
body: <p>I am writing some software (in C++, for Linux/Mac OSX) which runs as a non-privileged user but needs root privileges at some point (to create a new virtual device).</p>
  
  <p>Running this program as root is not a option (mainly for security issues) and I need to know the identity (uid) of the "real" user.</p>
  
  <p>Is there a way to mimic the "sudo" command behavior (ask for user password) to temporarily gain root privileges and perform the particular task ? If so, which functions would I use ?</p>
  
  <p>Thank you very much for your help !</p>