    {-
    symbolic links to the executable:

    Linux:
    /proc/<pid>/exe

    Solaris: (Solaris 10 only???)
    /proc/<pid>/object/a.out (filename only)
    /proc/<pid>/path/a.out (complete pathname)

    *BSD:
    /proc/<pid>/file
    -}

    {-# LANGUAGE ForeignFunctionInterface #-}

    module System.Environment.Executable.Linux
      ( getExecutablePath
      , getPID
      )
      where

    import Data.Bits
    import Data.Word
    import Data.Int

    import Control.Monad

    import Foreign
    import Foreign.C

    import System.Posix
    --import System.FilePath

    --------------------------------------------------------------------------------

    getPID :: IO Int
    getPID :: IO Int
    getPID = (ProcessID -> Int) -> IO ProcessID -> IO Int
    forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
    liftM ProcessID -> Int
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (IO ProcessID -> IO Int) -> IO ProcessID -> IO Int
    forall a b. (a -> b) -> a -> b
    $ IO ProcessID
    getProcessID

    getExecutablePath :: IO FilePath
    getExecutablePath :: IO FilePath
    getExecutablePath = do
      pid <- IO Int
    getPID
      fname <- readSymbolicLink $ "/proc/" ++ show pid ++ "/exe"
      --let (path,exename) = splitFileName fname
      --return path
      return fname

    --------------------------------------------------------------------------------