views:

91

answers:

1

Question:

I need to make some system calls in my C# applications. Unfortunately, this behaves differently on Linux than on UNIX.

Now I used to switch the Operating system at runtime like this

If Environment.OSVersion.Platform = System.PlatformID.Unix Then
    ' Linux/Unix '
ElseIf Environment.OSVersion.Platform = System.PlatformID.MacOSX Then
    ' Apple '
Else
    ' Windows '
End If

The problem now is I need to differentiate between UNIX and Linux, because they are different.

Is there a way I can figure out whether the OS is Linux or Unix? Preferably not by invoking uname -a

I wouldn't like to abandon Unix and make it Linux only, just because Microsoft did not add a PlatformID.Linux...

+5  A: 

You will need to use "uname -a" to distinguish Linux from Unix, as well as OSX. For historical reasons, Mono reports OSX as Unix, not MacOSX.

Some code that uses uname is available here: http://github.com/jpobst/Pinta/blob/master/Pinta/Platform.cs

jpobst
OS X a Unix. That's a bad joke - well unfortunately it's not a joke. It's missing the ENTIRE proc subsystem, and it also has a completely changed ptrace interface. Well, so much to 'preferably not by invoking uname -a'. +1 for the codesample, though.
Quandary
/proc is a linux-ism, not a unix-ism.
pra
@pra: True, it's not in the standard, but FreeBSD has it.
Quandary