{-# 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
getPID :: IO Int
getPID :: IO Int
getPID = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ IO ProcessID
getProcessID
getExecutablePath :: IO FilePath
getExecutablePath :: IO FilePath
getExecutablePath = do
Int
pid <- IO Int
getPID
FilePath
fname <- FilePath -> IO FilePath
readSymbolicLink forall a b. (a -> b) -> a -> b
$ FilePath
"/proc/" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> FilePath
show Int
pid forall a. [a] -> [a] -> [a]
++ FilePath
"/exe"
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
fname