On Unix, find if user who executed the program is root? On Unix, find if user who executed the program is root? bash bash

On Unix, find if user who executed the program is root?


Use uid or euid in the Process class:

raise 'Must run as root' unless Process.uid == 0


I don't know Ruby, but what you want to check for is if the user ID is 0. In C, you would do this by checking getuid(). From the Unix command line, you could also check the output of id -u.