diff options
author | tv <tv@shackspace.de> | 2014-11-04 00:00:40 +0100 |
---|---|---|
committer | tv <tv@shackspace.de> | 2014-11-04 00:00:40 +0100 |
commit | a1aa9ddd72dfdec47399f29319f821f542906365 (patch) | |
tree | b235d966ff561a649fb873072d5edd5969c082a6 /src/CGroup.hs | |
parent | 0f447cd62836a5f5b29b8e14263fde89f446f52b (diff) |
mv **.hs src/
Diffstat (limited to 'src/CGroup.hs')
-rw-r--r-- | src/CGroup.hs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/CGroup.hs b/src/CGroup.hs new file mode 100644 index 0000000..11b54cd --- /dev/null +++ b/src/CGroup.hs @@ -0,0 +1,53 @@ +-- | +-- Module: CGroup +-- Copyright: (c) 2014 Tomislav Viljetić +-- License: BSD3 +-- Maintainer: Tomislav Viljetić <tomislav@viljetic.de> +-- +-- Basic cgroup virtual filesystem operations. +-- + +module CGroup + ( module CGroup.Types + , createCGroup + , classifyTask + , listTasks + ) where + +import CGroup.Types +import Control.Applicative +import Data.Attoparsec.ByteString.Char8 +import Data.Set (Set) +import qualified Data.Set as Set +import System.Directory (createDirectory) +import System.FilePath ((</>)) +import System.IO.Streams.Attoparsec (parseFromStream) +import System.IO.Streams.File (withFileAsInput) + + +-- | Create a new cgroup. +createCGroup :: CGroup -> IO () +createCGroup = + createDirectory . cgroupPath + + +-- | Places a task into a cgroup. +classifyTask :: ProcessID -> CGroup -> IO () +classifyTask pid g = + writeFile (tasksFile g) (show pid) + + +-- | Retrieve the tasks of a cgroup. +listTasks :: CGroup -> IO (Set ProcessID) +listTasks g = + withFileAsInput (tasksFile g) $ parseFromStream tasksParser + + +tasksFile :: CGroup -> FilePath +tasksFile = + (</> "tasks") . cgroupPath + + +tasksParser :: Parser (Set ProcessID) +tasksParser = + Set.fromList <$> many' (decimal <* endOfLine) <* endOfInput <?> "tasks" |