Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make a C++ program on Ubuntu that checks if a user can shutdown the PC, and, if so, shut it down for him.

So, I'm thinking about getting the user ID, and then, checking if, or if not, he has the rights to shut down the computer.

However, I really don't know what is the critera in Ubuntu that says if a user has such a right ... do you happen to know what this is ?

Thanks !

share|improve this question
up vote 0 down vote accepted

I think I've found the solution to my problem, so now I'm posting it.

Testing admin privileges can be done like so :

uid_t uid = getuid(), euid = geteuid();
if(uid < 0 || uid != euid) {
    // Can stop or reboot system
} else {
    // Cannot stop nor reboot system
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.