amsatop packageο
Libraryο
amsatop package.
Exposes top-level components for creating your own htop
- class amsatop.Htop(proc_folder: str = '/proc')[source]ο
Bases:
ABC
Abstract base class representing a simplified version of the Unix βhtopβ utility.
This class defines the interface for interacting with system process information. It is designed to be subclassed by students or developers who will provide concrete implementations for the defined methods.
- proc_folderο
Path to the directory containing process information. Defaults to β/procβ, but can be overridden by setting the βPROC_FOLDERβ environment variable. You should allways use this variable and not β/procβ.
- Type:
str
- abstractmethod get_hup() List[Process] [source]ο
Retrieve processes that are eligible to ignore the SIGHUP signal.
- Returns:
A list of Process objects that ignore the SIGHUP signal.
- Raises:
NotImplementedError: If not implemented by subclass.
- abstractmethod get_priorities() List[Process] [source]ο
Retrieve all system processes along with their scheduling priorities.
- Returns:
A list of Process objects with priority information.
- Raises:
NotImplementedError: If not implemented by subclass.
- abstractmethod get_processes() List[Process] [source]ο
Retrieve all system processes, without the priority field
- Returns:
A list of Process objects representing all running processes.
- Raises:
NotImplementedError β If not implemented by subclass.
- proc_folder: strο
- class amsatop.HtopMock(proc_folder: str = '/proc')[source]ο
Bases:
Htop
Mock implementation of the Htop interface for testing or demonstration purposes.
This class simulates process information by returning hardcoded Process instances. Each method (get_processes, get_priorities, get_hup) returns a random subset of predefined mock processes.
Useful for testing code that depends on Htop without requiring access to the actual system process tree.
- RETURN_PROCESSES = 5ο
- get_hup() list[Process] [source]ο
Retrieve processes that are eligible to ignore the SIGHUP signal.
- Returns:
A list of Process objects that ignore the SIGHUP signal.
- Raises:
NotImplementedError: If not implemented by subclass.
- class amsatop.Process(pid: int, command: str, type: TaskType, priority: int | None)[source]ο
Bases:
object
Immutable data class representing a system process.
- Parameters:
pid (int) β The unique process ID.
command (str) β The command or executable that launched the process.
type (TaskType) β The type of the process
priority (int | None) β The scheduling priority of the process. Can be None if unavailable or youβre doing Prac-2.1 .
- command: strο
- pid: intο
- priority: int | Noneο
- class amsatop.TaskType(*values)[source]ο
Bases:
Enum
Enumeration of tasks types.
- KTHREAD = 'kthread'ο
- PROCESS = 'process'ο
- THREAD = 'thread'ο
- amsatop.run_ui(htop: Htop = None, refresh: int = 2) None [source]ο
Given an instance of htop, run the tui interface. By default, if no parameter is given, it launches the HtopMock implementation.
- Parameters:
htop β An instance of your htop implementation
refresh β The seconds between each table refresh, 2 by default
Utilitiesο
- amsatop.utils package
- Module contents
StatFile
StatFile.cmajflt
StatFile.cminflt
StatFile.command
StatFile.cstime
StatFile.cutime
StatFile.flags
StatFile.from_stat_line()
StatFile.majflt
StatFile.minflt
StatFile.nice
StatFile.num_threads
StatFile.pgrp
StatFile.pid
StatFile.ppid
StatFile.priority
StatFile.session
StatFile.starttime
StatFile.state
StatFile.stime
StatFile.tpgid
StatFile.tty_nr
StatFile.utime
StatusFile
StatusFile.CapAmb
StatusFile.CapBnd
StatusFile.CapEff
StatusFile.CapInh
StatusFile.CapPrm
StatusFile.CoreDumping
StatusFile.Cpus_allowed
StatusFile.Cpus_allowed_list
StatusFile.FDSize
StatusFile.Gid
StatusFile.Groups
StatusFile.HugetlbPages
StatusFile.Kthread
StatusFile.Mems_allowed
StatusFile.Mems_allowed_list
StatusFile.NSpgid
StatusFile.NSpid
StatusFile.NSsid
StatusFile.NStgid
StatusFile.Name
StatusFile.Ngid
StatusFile.NoNewPrivs
StatusFile.PPid
StatusFile.Pid
StatusFile.RssAnon
StatusFile.RssFile
StatusFile.RssShmem
StatusFile.Seccomp
StatusFile.Seccomp_filters
StatusFile.ShdPnd
StatusFile.SigBlk
StatusFile.SigCgt
StatusFile.SigIgn
StatusFile.SigPnd
StatusFile.SigQ
StatusFile.SpeculationIndirectBranch
StatusFile.Speculation_Store_Bypass
StatusFile.State
StatusFile.THP_enabled
StatusFile.Tgid
StatusFile.Threads
StatusFile.TracerPid
StatusFile.Uid
StatusFile.Umask
StatusFile.VmData
StatusFile.VmExe
StatusFile.VmHWM
StatusFile.VmLck
StatusFile.VmLib
StatusFile.VmPTE
StatusFile.VmPeak
StatusFile.VmPin
StatusFile.VmRSS
StatusFile.VmSize
StatusFile.VmStk
StatusFile.VmSwap
StatusFile.from_lines()
StatusFile.nonvoluntary_ctxt_switches
StatusFile.untag_mask
StatusFile.voluntary_ctxt_switches
StatusFile.x86_Thread_features
StatusFile.x86_Thread_features_locked
get_stat_file_from_path()
get_status_file_from_path()
- Module contents