Linux is easy, just call getuid() and/or geteuid(). "0" means the user is root (or that the application is suid root in the second case).