Need help with setuid

I'm writing a benchmark. To reduce performance variance, I want to run it with the highest priority. But since it requires root, I want to drop the privileges once they are not needed. I searched the net and couldn't find the solution to my problem though:
How do I obtain UID that I should feed setuid with?
The only answer that I found is to set setuid flag on the executable to always start it with root and then call setuid(getuid()). It's quite burdensome for users though. Is there any simple way of performing the simple task?
 
It's called Set User ID, it changes the account to the owner of the file. Hence, if the file is root owned it will SUID to root. If it's UserA it will SUID to UserA.

Be very, very careful with SUID root. If your application contains a bug someone might abuse it to escalate their privileges.

Developer's Handbook: 3.4 SetUID issues
 
SirDice said:
It's called Set User ID, it changes the account to the owner of the file. Hence, if the file is root owned it will SUID to root. If it's UserA it will SUID to UserA.

Be very, very careful with SUID root. If your application contains a bug someone might abuse it to escalate their privileges.

Developer's Handbook: 3.4 SetUID issues

I know that my bugs can cause harm when running as root and that's precisely the reason I want to use setuid(). I want to drop my rights as soon as I have my priority set.
 
Back
Top