There's gotta be some way to programmatically determine it, right? It may not be portable. It may require some system calls or something, but there's gotta be a way, right?
You can get away with just about anything if you do it in a child worker process which can safely crash.