Process p = Runtime.getRuntime().exec("id -u")
Keep in mind that the "root" user on a system may not be called root
(although it's rare to change it), and it's also possible to alias it to another username. If the current user is root-like, the output will be 0
.