procps-bindings-0.1.0.0: Haskell bindings to the procps library
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.Proc.Bindings

Description

Example

import Text.Show.Pretty
import System.Proc.Bindings
import System.Proc.Bindings.Tab

main :: IO ()
main = do
  let flags =
        fillMem
          <> fillCom
          <> fillUser
          <> fillGroup
          <> fillStatus
          <> fillStat
          <> fillArg
      procFilter = ByUids [1000]
      config = TableConfig flags procFilter

  result <- withProcTab config $ \proctab -> do
    info <- getProcTabInfo proctab
    pPrint info

    eProc <- readNextProc proctab
    case eProc of
      Left err -> print err
      Right proc -> pPrint proc

  case result of
    Left err -> print err
    Right _ -> pure ()

  pure ()

Output:

ProcTabInfo
  { didFake = False
  , pids = []
  , uids = [ 1000 ]
  , flags = 16763
  , path = ""
  }
Proc
  { taskId = 1962
  , parentPid = 1
  , userModeCPUTime = 5
  , startTimeInSeconds = 904
  , ...
  }
Synopsis

Process information

data Proc Source #

All the information we've read about a single process.

This is the "escape hatch" from all the funky C stuff, memory management, bracketed access etc: Proc is just a normal Haskell datatype without any pointers going on, so you can do what you want with it.

The fields of Proc come from proc_t, and are parsed from various files in the /proc/#/ directory.

For more detailed information, see the following man pages:

Instances

Instances details
Show Proc Source # 
Instance details

Defined in System.Proc.Bindings.C

Eq Proc Source # 
Instance details

Defined in System.Proc.Bindings.C

Methods

(==) :: Proc -> Proc -> Bool Source #

(/=) :: Proc -> Proc -> Bool Source #

Read the current process

readSelfProc :: HasCallStack => IO (Either ProcError Proc) Source #

Try to read a Proc representing the current proces or task.

Read all processes

readAllProcsLenient :: HasCallStack => TableConfig -> IO [Proc] Source #

Read all the Procs according to a TableConfig. Errors are ignored.

Process table

data ProcTab Source #

The proctab (process table) is a persistent handle-like data structure holding the information the library needs to read process information. While Procs are typically ephemeral, the ProcTab is more long lived.

Typically it will be created and populated by openProcTab (or withProcTab, which handles memory management); the TableConfig tells the underlying library what information we want to read, but no actual process information is read yet.

We then query the ProcTab for information about processes, using functions like readNextProc or readNextProcInfo

Concrete process information

taskId :: Proc -> CInt Source #

Task ID, the POSIX thread ID (see also: threadGroupId).

Always read.

parentPid :: Proc -> CInt Source #

Process ID of parent process.

Read when flagStat or flagStatus.

majDelta :: Proc -> CULong Source #

Major page faults since last update.

Read when flagStat (special).

minDelta :: Proc -> CULong Source #

Minor page faults since last update.

Read when flagStat (special).

cpuUsagePercent :: Proc -> CUInt Source #

%CPU usage (is not filled in by readNextProc).

Read when flagStat (special).

processStateCode :: Proc -> CChar Source #

Single-char code for process state.

Read when flagStat or flagStatus.

From proc_pid_stat:

 R      Running

 S      Sleeping in an interruptible wait

 D      Waiting in uninterruptible disk sleep

 Z      Zombie

 T      Stopped (on a signal) or (before Linux 2.6.33) trace stopped

 t      Tracing stop (Linux 2.6.33 onward)

 W      Paging (only before Linux 2.6.0)

 X      Dead (from Linux 2.6.0 onward)

 x      Dead (Linux 2.6.33 to 3.13 only)

 K      Wakekill (Linux 2.6.33 to 3.13 only)

 W      Waking (Linux 2.6.33 to 3.13 only)

 P      Parked (Linux 3.9 to 3.13 only)

 I      Idle (Linux 4.14 onward)
 

userModeCPUTime :: Proc -> CULLong Source #

User-mode CPU time accumulated by process.

Read when flagStat.

kernelModeCPUTime :: Proc -> CULLong Source #

Kernel-mode CPU time accumulated by process.

Read when flagStat.

cumulativeUserModeCPUTime :: Proc -> CULLong Source #

Cumulative utime of process and reaped children.

Read when flagStat.

cumulativeKernelModeCPUTime :: Proc -> CULLong Source #

Cumulative stime of process and reaped children.

Read when flagStat.

startTimeInSeconds :: Proc -> CULLong Source #

Start time of process: seconds since system boot.

Read when flagStat.

type SignalMask = Maybe String Source #

The reason we type alias this is because the procps library will use a different type to represent signal masks depending on whether the SIGNAL_STRING macro is defined.

Specifically:

ifdef SIGNAL_STRING
type SignalMask = Maybe String
else
type SignalMask = CLLong
endif

pendingSignalMask :: Proc -> SignalMask Source #

Mask of pending signals, per-task for readtask() but per-proc for readproc().

Read when fillStatus.

blockSignalMask :: Proc -> SignalMask Source #

Mask of blocked signals.

Read when fillStatus.

ignoredSignalMask :: Proc -> SignalMask Source #

Mask of ignored signals.

Read when fillStatus.

caughtSignalMask :: Proc -> SignalMask Source #

Mask of caught signals.

Read when fillStatus.

perTaskPendingSignals :: Proc -> SignalMask Source #

Mask of per task pending signals.

Read when fillStatus.

type Address = CULong Source #

The reason we type alias this is because the procps library will use a different type to represent addresses depending on the system and some other C macro stuff.

Specifically:

if defined(k64test) || (defined(_ABIN32) && _MIPS_SIM == _ABIN32)
type Address = CULLong
else
type Address = CULong
endif

codeStartAddress :: Proc -> Address Source #

Address of beginning of code segment.

Read when flagStat.

codeEndAddress :: Proc -> Address Source #

Address of end of code segment.

Read when flagStat.

stackBottomAddress :: Proc -> Address Source #

Address of the bottom of stack for the process.

Read when flagStat.

kernelStackPointer :: Proc -> Address Source #

Kernel stack pointer.

Read when flagStat.

kernelInstructionPointer :: Proc -> Address Source #

Kernel instruction pointer.

Read when flagStat.

kernelWaitChannelAddress :: Proc -> Address Source #

Address of kernel wait channel proc is sleeping in.

Read when flagStat (special).

kernelSchedulingPriority :: Proc -> CLong Source #

Kernel scheduling priority.

Read when flagStat.

niceLevel :: Proc -> CLong Source #

Standard unix nice level of process.

Read when flagStat.

alarm :: Proc -> CLong Source #

Not used since Linux 2.6.17.

Read when flagStat.

From proc_pid_stat:

 The time in jiffies before the next SIGALRM is sent
 to the process due to an interval timer.  Since
 Linux 2.6.17, this field is no longer maintained,
 and is hard coded as 0.
 

totalVirtualMemInPages :: Proc -> CLong Source #

Total virtual memory (as # pages).

Read when flagMem.

residentNonSwappedMemInPages :: Proc -> CLong Source #

Resident non-swapped memory (as # pages).

Read when flagMem.

sharedMemInPages :: Proc -> CLong Source #

Shared (mmap'd) memory (as # pages).

Read when flagMem.

textResidentSetInPages :: Proc -> CLong Source #

Text (exe) resident set (as # pages).

Read when flagMem.

libraryResidentSetInPages :: Proc -> CLong Source #

Library resident set (always 0 w/ 2.6).

Read when flagMem.

dataAndStackResidentSetInPages :: Proc -> CLong Source #

Data+stack resident set (as # pages).

Read when flagMem.

dirtyPages :: Proc -> CLong Source #

Dirty pages (always 0 w/ 2.6).

Read when flagMem.

vmLockedPagesInKb :: Proc -> CULong Source #

Locked pages (as kb).

Read when fillStatus.

vmRssInKb :: Proc -> CULong Source #

Equals rss and/or residentNonSwappedMemInPages (as kb).

Read when fillStatus.

vmRssAnonInKb :: Proc -> CULong Source #

The anonymous portion of vm_rss (as kb).

Read when fillStatus.

vmRssFileBackedInKb :: Proc -> CULong Source #

The file-backed portion of vm_rss (as kb).

Read when fillStatus.

vmRssSharedInKb :: Proc -> CULong Source #

The shared portion of vm_rss (as kb).

Read when fillStatus.

vmDataSizeInKb :: Proc -> CULong Source #

Data only size (as kb).

Read when fillStatus.

vmStackSizeInKb :: Proc -> CULong Source #

Stack only size (as kb).

Read when fillStatus.

vmSwapSizeInKb :: Proc -> CULong Source #

Based on linux-2.6.34 "swap ents" (as kb).

Read when fillStatus.

vmTotalLibraryPagesInKb :: Proc -> CULong Source #

Total, not just used, library pages (as kb).

Read when fillStatus.

realTimePriority :: Proc -> CULong Source #

Real-time priority.

Read when flagStat.

schedulingClass :: Proc -> CULong Source #

Scheduling class.

Read when flagStat.

virtualMemoryInPages :: Proc -> CULong Source #

Number of pages of virtual memory.

Read when flagStat.

residentSetSizeLimit :: Proc -> CULong Source #

Resident set size limit?

Read when flagStat.

kernelFlags :: Proc -> CULong Source #

Kernel flags for the process.

Read when flagStat.

minorPageFaults :: Proc -> CULong Source #

Number of minor page faults since process start.

Read when flagStat.

majorPageFaults :: Proc -> CULong Source #

Number of major page faults since process start.

Read when flagStat.

cumulativeMinorPageFaults :: Proc -> CULong Source #

Cumulative min_flt of process and child processes.

Read when flagStat.

cumulativeMajorPageFaults :: Proc -> CULong Source #

Cumulative maj_flt of process and child processes.

Read when flagStat.

environment :: Proc -> [String] Source #

Environment string vector (proc#/environ).

Read when flagEnviron.

cmdline :: Proc -> [String] Source #

Command line string vector (proc#/cmdline).

Read when fillCom or fillArg.

cgroup :: Proc -> [String] Source #

Cgroup string vector (proc#/cgroup).

Read when flagCGroup.

cgroupName :: Proc -> Maybe String Source #

Name portion of above (if possible).

Read when flagCGroup and not editCGroupAsSingleVector.

supplementaryGids :: Proc -> Maybe String Source #

Supplementary gids as comma delimited str.

Read when fillStatus.

supplementaryGroupNames :: Proc -> Maybe String Source #

Supp grp names as comma delimited str, derived from supgid.

effectiveUserName :: Proc -> Maybe String Source #

Effective user name.

Read when flagStat or flagStatus.

realUserName :: Proc -> Maybe String Source #

Real user name.

Read when fillStatus.

savedUserName :: Proc -> Maybe String Source #

Saved user name.

Read when fillStatus.

filesystemUserName :: Proc -> Maybe String Source #

Filesystem user name.

Read when fillStatus.

realGroupName :: Proc -> Maybe String Source #

Real group name.

Read when fillStatus.

effectiveGroupname :: Proc -> Maybe String Source #

Effective group name.

Read when fillStatus.

savedGroupName :: Proc -> Maybe String Source #

Saved group name.

Read when fillStatus.

filesystemGroupName :: Proc -> Maybe String Source #

Filesystem group name.

Read when fillStatus.

cmd :: Proc -> Maybe String Source #

Basename of executable file in call to exec(2).

Read when flagStat or flagStatus.

processGroupId :: Proc -> CInt Source #

Process group ID.

Read when flagStat.

sessionId :: Proc -> CInt Source #

Session ID.

Read when flagStat.

numberOfThreasds :: Proc -> CInt Source #

Number of threads, or 0 if no clue.

Read when flagStat or flagStatus.

threadGroupId :: Proc -> CInt Source #

Thread group ID, the POSIX PID (see also: taskId).

Always read.

ttyNumber :: Proc -> CInt Source #

Full device number of controlling terminal.

Read when flagStat.

effectiveUserId :: Proc -> CInt Source #

Effective user ID.

Read when flagStat or flagStatus.

effectiveGroupId :: Proc -> CInt Source #

Effective group ID.

Read when flagStat or flagStatus.

realUserId :: Proc -> CInt Source #

Real user ID.

Read when fillStatus.

realGroupId :: Proc -> CInt Source #

Real group ID.

Read when fillStatus.

savedUserId :: Proc -> CInt Source #

Saved user ID.

Read when fillStatus.

savedGroupId :: Proc -> CInt Source #

Saved group ID.

Read when fillStatus.

filesystemUserId :: Proc -> CInt Source #

Fs user ID (used for file access only).

Read when fillStatus.

filesystemGroupId :: Proc -> CInt Source #

Fs group ID (used for file access only).

Read when fillStatus.

terminalProcessGroupId :: Proc -> CInt Source #

Terminal process group ID.

Read when flagStat.

exitSignal :: Proc -> CInt Source #

Might not be SIGCHLD.

Read when flagStat.

cpu :: Proc -> CInt Source #

Current (or most recent?) CPU.

Read when flagStat.

oomScore :: Proc -> CInt Source #

(badness for OOM killer).

Read when flagOOM.

oomAdjustment :: Proc -> CInt Source #

(adjustment to OOM score).

Read when flagOOM.

namespaces :: Proc -> [CLong] Source #

Inode number of namespaces.

Read when flagNS.

systemdContainerName :: Proc -> Maybe String Source #

Systemd vm/container name.

systemdSessionOwnerUid :: Proc -> Maybe String Source #

Systemd session owner uid.

systemdLoginSessionSeat :: Proc -> Maybe String Source #

Systemd login session seat.

systemdLoginSessionId :: Proc -> Maybe String Source #

Systemd login session ID.

systemdSliceUnit :: Proc -> Maybe String Source #

Systemd slice unit.

systemdSystemUnitId :: Proc -> Maybe String Source #

Systemd system unit ID.

systemdUserUnitId :: Proc -> Maybe String Source #

Systemd user unit ID.

lxcContainerName :: Proc -> Maybe String Source #

Lxc container name.