| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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
- data Proc
- readSelfProc :: HasCallStack => IO (Either ProcError Proc)
- readAllProcs :: HasCallStack => TableConfig -> IO [Either ProcError Proc]
- readAllProcsLenient :: HasCallStack => TableConfig -> IO [Proc]
- data ProcTab
- readNextProc :: HasCallStack => ProcTab -> IO (Either ProcError Proc)
- taskId :: Proc -> CInt
- parentPid :: Proc -> CInt
- majDelta :: Proc -> CULong
- minDelta :: Proc -> CULong
- cpuUsagePercent :: Proc -> CUInt
- processStateCode :: Proc -> CChar
- userModeCPUTime :: Proc -> CULLong
- kernelModeCPUTime :: Proc -> CULLong
- cumulativeUserModeCPUTime :: Proc -> CULLong
- cumulativeKernelModeCPUTime :: Proc -> CULLong
- startTimeInSeconds :: Proc -> CULLong
- type SignalMask = Maybe String
- pendingSignalMask :: Proc -> SignalMask
- blockSignalMask :: Proc -> SignalMask
- ignoredSignalMask :: Proc -> SignalMask
- caughtSignalMask :: Proc -> SignalMask
- perTaskPendingSignals :: Proc -> SignalMask
- type Address = CULong
- codeStartAddress :: Proc -> Address
- codeEndAddress :: Proc -> Address
- stackBottomAddress :: Proc -> Address
- kernelStackPointer :: Proc -> Address
- kernelInstructionPointer :: Proc -> Address
- kernelWaitChannelAddress :: Proc -> Address
- kernelSchedulingPriority :: Proc -> CLong
- niceLevel :: Proc -> CLong
- rss :: Proc -> CLong
- alarm :: Proc -> CLong
- totalVirtualMemInPages :: Proc -> CLong
- residentNonSwappedMemInPages :: Proc -> CLong
- sharedMemInPages :: Proc -> CLong
- textResidentSetInPages :: Proc -> CLong
- libraryResidentSetInPages :: Proc -> CLong
- dataAndStackResidentSetInPages :: Proc -> CLong
- dirtyPages :: Proc -> CLong
- vmSizeInKb :: Proc -> CULong
- vmLockedPagesInKb :: Proc -> CULong
- vmRssInKb :: Proc -> CULong
- vmRssAnonInKb :: Proc -> CULong
- vmRssFileBackedInKb :: Proc -> CULong
- vmRssSharedInKb :: Proc -> CULong
- vmDataSizeInKb :: Proc -> CULong
- vmStackSizeInKb :: Proc -> CULong
- vmSwapSizeInKb :: Proc -> CULong
- vmExeInKb :: Proc -> CULong
- vmTotalLibraryPagesInKb :: Proc -> CULong
- realTimePriority :: Proc -> CULong
- schedulingClass :: Proc -> CULong
- virtualMemoryInPages :: Proc -> CULong
- residentSetSizeLimit :: Proc -> CULong
- kernelFlags :: Proc -> CULong
- minorPageFaults :: Proc -> CULong
- majorPageFaults :: Proc -> CULong
- cumulativeMinorPageFaults :: Proc -> CULong
- cumulativeMajorPageFaults :: Proc -> CULong
- environment :: Proc -> [String]
- cmdline :: Proc -> [String]
- cgroup :: Proc -> [String]
- cgroupName :: Proc -> Maybe String
- supplementaryGids :: Proc -> Maybe String
- supplementaryGroupNames :: Proc -> Maybe String
- effectiveUserName :: Proc -> Maybe String
- realUserName :: Proc -> Maybe String
- savedUserName :: Proc -> Maybe String
- filesystemUserName :: Proc -> Maybe String
- realGroupName :: Proc -> Maybe String
- effectiveGroupname :: Proc -> Maybe String
- savedGroupName :: Proc -> Maybe String
- filesystemGroupName :: Proc -> Maybe String
- cmd :: Proc -> Maybe String
- processGroupId :: Proc -> CInt
- sessionId :: Proc -> CInt
- numberOfThreasds :: Proc -> CInt
- threadGroupId :: Proc -> CInt
- ttyNumber :: Proc -> CInt
- effectiveUserId :: Proc -> CInt
- effectiveGroupId :: Proc -> CInt
- realUserId :: Proc -> CInt
- realGroupId :: Proc -> CInt
- savedUserId :: Proc -> CInt
- savedGroupId :: Proc -> CInt
- filesystemUserId :: Proc -> CInt
- filesystemGroupId :: Proc -> CInt
- terminalProcessGroupId :: Proc -> CInt
- exitSignal :: Proc -> CInt
- cpu :: Proc -> CInt
- oomScore :: Proc -> CInt
- oomAdjustment :: Proc -> CInt
- namespaces :: Proc -> [CLong]
- systemdContainerName :: Proc -> Maybe String
- systemdSessionOwnerUid :: Proc -> Maybe String
- systemdLoginSessionSeat :: Proc -> Maybe String
- systemdLoginSessionId :: Proc -> Maybe String
- systemdSliceUnit :: Proc -> Maybe String
- systemdSystemUnitId :: Proc -> Maybe String
- systemdUserUnitId :: Proc -> Maybe String
- lxcContainerName :: Proc -> Maybe String
Process information
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:
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
readAllProcs :: HasCallStack => TableConfig -> IO [Either ProcError Proc] Source #
Read all the Procs according to a TableConfig.
readAllProcsLenient :: HasCallStack => TableConfig -> IO [Proc] Source #
Read all the Procs according to a TableConfig.
Errors are ignored.
Process table
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
readNextProc :: HasCallStack => ProcTab -> IO (Either ProcError Proc) Source #
Concrete process information
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.
codeStartAddress :: Proc -> Address Source #
Address of beginning of code segment.
Read when flagStat.
stackBottomAddress :: Proc -> Address Source #
Address of the bottom of stack for the process.
Read when flagStat.
kernelWaitChannelAddress :: Proc -> Address Source #
Address of kernel wait channel proc is sleeping in.
Read when flagStat (special).
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.
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.
vmSizeInKb :: Proc -> CULong Source #
Equals totalVirtualMemInPages (as kb).
Read when fillStatus.
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.
vmExeInKb :: Proc -> CULong Source #
Equals textResidentSetInPages (as kb).
Read when fillStatus.
vmTotalLibraryPagesInKb :: Proc -> CULong Source #
Total, not just used, library pages (as kb).
Read when fillStatus.
virtualMemoryInPages :: Proc -> CULong Source #
Number of pages of virtual memory.
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.
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.
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.
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.