Rudiments
Static Public Member Functions | List of all members
sys Class Reference

Static Public Member Functions

static char * getOperatingSystemName ()
 
static char * getOperatingSystemRelease ()
 
static char * getOperatingSystemVersion ()
 
static char * getOperatingSystemArchitecture ()
 
static bool isBigEndian ()
 
static const char * getRudimentsVersion ()
 
static char * getHostName ()
 
static bool setHostName (const char *hostname)
 
static bool setHostName (const char *hostname, uint64_t hostnamelen)
 
static bool getLoadAverages (double *oneminuteaverage, double *fiveminuteaverage, double *fifteenminuteaverage)
 
static void sync ()
 
static bool halt ()
 
static bool shutDown ()
 
static bool reboot ()
 
static int64_t getMaxCommandLineArgumentLength ()
 
static int64_t getMaxProcessesPerUser ()
 
static int64_t getMaxHostNameLength ()
 
static int64_t getMaxLoginNameLength ()
 
static int64_t getClockTicksPerSecond ()
 
static int64_t getMaxOpenFilesPerProcess ()
 
static int32_t getPageSize ()
 
static int32_t getAllocationGranularity ()
 
static int64_t getMaxOpenStreamsPerProcess ()
 
static int64_t getMaxSymlinkLoops ()
 
static int64_t getMaxTerminalDeviceNameLength ()
 
static int64_t getMaxTimezoneNameLength ()
 
static int64_t getMaxLineLength ()
 
static int64_t getPhysicalPageCount ()
 
static int64_t getAvailablePhysicalPageCount ()
 
static int64_t getUsedPhysicalPageCount ()
 
static int64_t getPhysicalMemorySize ()
 
static int64_t getAvailablePhysicalMemorySize ()
 
static int64_t getUsedPhysicalMemorySize ()
 
static int64_t getProcessorCount ()
 
static int64_t getMaxProcessorCount ()
 
static int64_t getProcessorsOnline ()
 
static int64_t getMaxSupplementalGroupsPerUser ()
 
static int64_t getMaxDelayTimerExpirations ()
 
static int64_t getMaxRealtimeSignals ()
 
static int64_t getMaxSemaphoresPerProcess ()
 
static int64_t getMaxSemaphoreValue ()
 
static int64_t getMaxSignalQueueLength ()
 
static int64_t getMaxTimersPerProcess ()
 
static int64_t getSuggestedGroupEntryBufferSize ()
 
static int64_t getSuggestedPasswordEntryBufferSize ()
 
static int64_t getMinThreadStackSize ()
 
static int64_t getMaxThreadsPerProcess ()
 
static int64_t getThreadDestructorIterations ()
 
static int64_t getMaxThreadKeys ()
 
static int64_t getMaxAtExitFunctions ()
 
static int64_t getCpuSetSize ()
 
static int64_t getMaxPasswordLength ()
 
static int64_t getMaxLogNameLength ()
 
static int64_t getMaxProcessId ()
 
static int64_t sysConf (int32_t name)
 
static bool getSignalsInterruptSystemCalls ()
 
static char getDirectorySeparator ()
 
static bool setProtection (byte_t *ptr, size_t size, int32_t protection)
 
static bool adviseSequentialAccess (byte_t *ptr, size_t size)
 
static bool adviseRandomAccess (byte_t *ptr, size_t size)
 
static bool adviseWillNeed (byte_t *ptr, size_t size)
 
static bool adviseWontNeed (byte_t *ptr, size_t size)
 
static bool adviseNormalAccess (byte_t *ptr, size_t size)
 
static bool disablePaging (byte_t *ptr, size_t size)
 
static bool enablePaging (byte_t *ptr, size_t size)
 
static bool getNotPagedOut (byte_t *ptr, size_t size)
 
static bool disablePaging ()
 
static bool disablePagingOfCurrent ()
 
static bool disablePagingOfNew ()
 
static bool enablePaging ()
 
static size_t getMinSizeT ()
 
static size_t getMaxSizeT ()
 
static ssize_t getMinSSizeT ()
 
static ssize_t getMaxSSizeT ()
 
static off64_t getMinOff64T ()
 
static off64_t getMaxOff64T ()
 

Detailed Description

The sys class provides methods for controlling the state of and accessing information about the operating system.

Member Function Documentation

◆ adviseNormalAccess()

static bool sys::adviseNormalAccess ( byte_t *  ptr,
size_t  size 
)
static

Advises the kernel that you are going to access the region of memory begining at byte "ptr", for "size" bytes, normally so the kernel can undo any previously applied optimizations.

Returns true on success and false on failure.

On operating systems don't support this method, it returns true but don't actually do anything.

◆ adviseRandomAccess()

static bool sys::adviseRandomAccess ( byte_t *  ptr,
size_t  size 
)
static

Advises the kernel that you are going to access the region of memory begining at byte "ptr", for "size" bytes, randomly so the kernel can perform some optimizations.

Returns true on success and false on failure.

On operating systems don't support this method, it returns true but don't actually do anything.

◆ adviseSequentialAccess()

static bool sys::adviseSequentialAccess ( byte_t *  ptr,
size_t  size 
)
static

Advises the kernel that you are going to access the region of memory begining at byte "ptr", for "size" bytes, sequentially so the kernel can perform some optimizations.

Returns true on success and false on failure.

On operating systems don't support this method, it returns true but don't actually do anything.

◆ adviseWillNeed()

static bool sys::adviseWillNeed ( byte_t *  ptr,
size_t  size 
)
static

Advises the kernel that you are going to access the region of memory begining at byte "ptr", for "size" bytes, in the near future so the kernel can perform some optimizations.

Returns true on success and false on failure.

On operating systems don't support this method, it returns true but don't actually do anything.

◆ adviseWontNeed()

static bool sys::adviseWontNeed ( byte_t *  ptr,
size_t  size 
)
static

Advises the kernel that you are not going to access the region of memory begining at byte "ptr", for "size" bytes, in the near future so the kernel can perform some optimizations.

Returns true on success and false on failure.

On operating systems don't support this method, it returns true but don't actually do anything.

◆ disablePaging() [1/2]

static bool sys::disablePaging ( )
static

Disables paging of the entire address space of the process, including any newly allocated pages.

Returns true on success and false on failure.

On systems that don't support locking, this method returns false;

◆ disablePaging() [2/2]

static bool sys::disablePaging ( byte_t *  ptr,
size_t  size 
)
static

Disables paging of memory, starting at "ptr", for "size" bytes.

Returns true on success and false on failure.

On systems that don't support disabling paging, this method returns false.

◆ disablePagingOfCurrent()

static bool sys::disablePagingOfCurrent ( )
static

Disables paging of the entire address space of the process. Newly allocated pages may still be paged out.

Returns true on success and false on failure.

On systems that don't support locking, this method returns false;

◆ disablePagingOfNew()

static bool sys::disablePagingOfNew ( )
static

Disables paging of any newly allocated pages in the address space of the process. Currently allocated pages may still be paged out.

Returns true on success and false on failure.

On systems that don't support locking, this method returns false;

◆ enablePaging() [1/2]

static bool sys::enablePaging ( )
static

Enables paging of all pages of the address space of the process.

Returns true on success and false on failure.

On systems that don't support locking, this method returns false;

◆ enablePaging() [2/2]

static bool sys::enablePaging ( byte_t *  ptr,
size_t  size 
)
static

Enables paging of memory, starting at "ptr", for "size" bytes.

Returns true on success and false on failure.

On systems that don't support disabling paging, this method returns false.

◆ getAllocationGranularity()

static int32_t sys::getAllocationGranularity ( )
static

Returns the allocation granularity, in bytes. Allocation granularity is the minimum number of bytes that a program's address space can be extended by. It's usually the same as the page size, but not on Windows, for example. Returns -1 if not supported by the system.

◆ getAvailablePhysicalMemorySize()

static int64_t sys::getAvailablePhysicalMemorySize ( )
static

Returns the number of bytes of physical memory that are available. Returns -1 if not supported by the system.

◆ getAvailablePhysicalPageCount()

static int64_t sys::getAvailablePhysicalPageCount ( )
static

Returns the number of pages of physical memory that are available. Returns -1 if not supported by the system.

◆ getClockTicksPerSecond()

static int64_t sys::getClockTicksPerSecond ( )
static

Returns the number of clock ticks per second - in particular, the number of times per second that the kernel interrupts the CPU(s) to perform process accounting and other tasks. Some kernels are "tickless" though, and the kernel is only interrupted on-demand. This method returns whatever the kernel reports, though some kernels report a value, whether it is valid or not. Returns -1 if not supported by the system.

◆ getCpuSetSize()

static int64_t sys::getCpuSetSize ( )
static

Returns the number of CPU's that can be bound together in a single CPU Set. Returns -1 if not supported by the system.

◆ getDirectorySeparator()

static char sys::getDirectorySeparator ( )
static

Returns the character used to separate directories in a path.

◆ getHostName()

static char* sys::getHostName ( )
static

Returns the host name of the machine that the program is running on, as understood by the kernel. This may or may not necessarily be the name the machine is known by on the network.

◆ getLoadAverages()

static bool sys::getLoadAverages ( double *  oneminuteaverage,
double *  fiveminuteaverage,
double *  fifteenminuteaverage 
)
static

Sets the parameters to the load averages from the past one, five and fifteen minutes. Returns true on success and false on failure.

◆ getMaxAtExitFunctions()

static int64_t sys::getMaxAtExitFunctions ( )
static

Returns the maximum number of functions that can be registered to run when the process exits. Returns -1 if not supported by the system.

◆ getMaxCommandLineArgumentLength()

static int64_t sys::getMaxCommandLineArgumentLength ( )
static

Returns the maximum character length of each command line argument. Returns -1 if not supported by the system.

◆ getMaxDelayTimerExpirations()

static int64_t sys::getMaxDelayTimerExpirations ( )
static

Returns the maximum number of delay timer expiration overruns. Returns -1 if not supported by the system.

◆ getMaxHostNameLength()

static int64_t sys::getMaxHostNameLength ( )
static

Returns the maximum character length allowed for the host name, not including the null terminator. Returns -1 if not supported by the system.

◆ getMaxLineLength()

static int64_t sys::getMaxLineLength ( )
static

Returns the maximum character length of a utility's input line length, either from standard input or from a file, including the trailing newline. Returns -1 if not supported by the system.

◆ getMaxLoginNameLength()

static int64_t sys::getMaxLoginNameLength ( )
static

Returns the maximum character length allowed for a login name, not including the null terminator. Returns -1 if not supported by the system.

◆ getMaxLogNameLength()

static int64_t sys::getMaxLogNameLength ( )
static

Returns the maximum character length that a password can be. Returns -1 if not supported by the system.

◆ getMaxOff64T()

off64_t sys::getMaxOff64T ( )
inlinestatic

Returns the maximum value that an off64_t can store on this platform.

◆ getMaxOpenFilesPerProcess()

static int64_t sys::getMaxOpenFilesPerProcess ( )
static

Returns the maximum number of files that a single process can have open simultaneously. Returns -1 if not supported by the system.

◆ getMaxOpenStreamsPerProcess()

static int64_t sys::getMaxOpenStreamsPerProcess ( )
static

Returns the maximum number of streams that a single process can have open simultaneously. Returns -1 if not supported by the system.

◆ getMaxPasswordLength()

static int64_t sys::getMaxPasswordLength ( )
static

Returns the maximum character length that a password can be. Returns -1 if not supported by the system.

◆ getMaxProcessesPerUser()

static int64_t sys::getMaxProcessesPerUser ( )
static

Returns the maximum number of processes that may run concurrently by each user. Returns -1 if not supported by the system.

◆ getMaxProcessId()

static int64_t sys::getMaxProcessId ( )
static

Returns the maximum character length that a login name can be. Returns -1 if not supported by the system.

◆ getMaxProcessorCount()

static int64_t sys::getMaxProcessorCount ( )
static

Returns the maximum number of processors the system can possibly be configured to support. Returns -1 if not supported by the system.

◆ getMaxRealtimeSignals()

static int64_t sys::getMaxRealtimeSignals ( )
static

Returns the maximum number of realtime signals that are reserved for application use. Returns -1 if not supported by the system.

◆ getMaxSemaphoresPerProcess()

static int64_t sys::getMaxSemaphoresPerProcess ( )
static

Returns the maximum number of semaphores that a single process can have open simultaneously. Returns -1 if not supported by the system.

◆ getMaxSemaphoreValue()

static int64_t sys::getMaxSemaphoreValue ( )
static

Returns the maximum value that a semaphore can have. Returns -1 if not supported by the system.

◆ getMaxSignalQueueLength()

static int64_t sys::getMaxSignalQueueLength ( )
static

Returns the maximum number of signals that a single process can have pending at once. Returns -1 if not supported by the system.

◆ getMaxSizeT()

size_t sys::getMaxSizeT ( )
inlinestatic

Returns the maximum value that a size_t can store on this platform.

◆ getMaxSSizeT()

ssize_t sys::getMaxSSizeT ( )
inlinestatic

Returns the maximum value that a ssize_t can store on this platform.

◆ getMaxSupplementalGroupsPerUser()

static int64_t sys::getMaxSupplementalGroupsPerUser ( )
static

Returns the maximum number of groups that a user can be a member of, aside from its primary group. Returns -1 if not supported by the system.

◆ getMaxSymlinkLoops()

static int64_t sys::getMaxSymlinkLoops ( )
static

Returns the maximum number of symlinks that a pathname can resolve to before resolution returns ELOOP. This is useful for detecting symlink loops.

For instance, this value is used by cat in the following example:

$ ln -s file otherfile $ ln -s otherfile file $ cat file cat: file: Too many levels of symbolic links

Returns -1 if not supported by the system.

◆ getMaxTerminalDeviceNameLength()

static int64_t sys::getMaxTerminalDeviceNameLength ( )
static

Returns the maximum character length of a terminal device name, including the null terminator. Returns -1 if not supported by the system.

◆ getMaxThreadKeys()

static int64_t sys::getMaxThreadKeys ( )
static

Returns the maximum number of keys per process. Returns -1 if not supported by the system.

◆ getMaxThreadsPerProcess()

static int64_t sys::getMaxThreadsPerProcess ( )
static

Returns the maximum number of threads that a single process can have open simultaneously. Returns -1 if not supported by the system.

◆ getMaxTimersPerProcess()

static int64_t sys::getMaxTimersPerProcess ( )
static

Returns the maximum number of timers that a single process can have running at once. Returns -1 if not supported by the system.

◆ getMaxTimezoneNameLength()

static int64_t sys::getMaxTimezoneNameLength ( )
static

Returns the maximum character length of a timezone name. Returns -1 if not supported by the system.

◆ getMinOff64T()

off64_t sys::getMinOff64T ( )
inlinestatic

Returns the minimum value that an off64_t can store on this platform.

◆ getMinSizeT()

size_t sys::getMinSizeT ( )
inlinestatic

Returns the minimum value that a size_t can store on this platform.

◆ getMinSSizeT()

ssize_t sys::getMinSSizeT ( )
inlinestatic

Returns the minimum value that a ssize_t can store on this platform.

◆ getMinThreadStackSize()

static int64_t sys::getMinThreadStackSize ( )
static

Returns the minimum size, in bytes, of the stack for each thread. Returns -1 if not supported by the system.

◆ getNotPagedOut()

static bool sys::getNotPagedOut ( byte_t *  ptr,
size_t  size 
)
static

Returns true if all pages of memory starting at "ptr", for "size" bytes are not paged out.

Returns true on success and false on failure.

On systems that don't support checking whether pages of the memory map are currently cached in system ram, this method returns false.

◆ getOperatingSystemArchitecture()

static char* sys::getOperatingSystemArchitecture ( )
static

Returns the hardware architecture of the environment that the program is running in. i386, x86_64, ppc, etc.

◆ getOperatingSystemName()

static char* sys::getOperatingSystemName ( )
static

Returns the name of the operating system. Linux, FreeBSD, Windows, Cygwin, etc.

◆ getOperatingSystemRelease()

static char* sys::getOperatingSystemRelease ( )
static

Returns a string representing the operating system release. Exactly what is returned varies significantly between operating systems.

◆ getOperatingSystemVersion()

static char* sys::getOperatingSystemVersion ( )
static

Returns a string representing the operating system version. Exactly what is returned varies significantly between operating systems.

◆ getPageSize()

static int32_t sys::getPageSize ( )
static

Returns the page size, in bytes. NOTE: If you're looking for the minimum number of bytes that a programs address space can be extended by, see getAllocationGranularity() instead. On most platforms it's the same as the page size, but it's different on Windows, for example, Returns -1 if not supported by the system.

◆ getPhysicalMemorySize()

static int64_t sys::getPhysicalMemorySize ( )
static

Returns the number of bytes of physical memory, not including swap. Returns -1 if not supported by the system.

◆ getPhysicalPageCount()

static int64_t sys::getPhysicalPageCount ( )
static

Returns the number of pages of physical memory, not including swap. Returns -1 if not supported by the system.

◆ getProcessorCount()

static int64_t sys::getProcessorCount ( )
static

Returns the number of processors the system is configured to support. Returns -1 if not supported by the system.

◆ getProcessorsOnline()

static int64_t sys::getProcessorsOnline ( )
static

Returns the number of processors that are currently online. Returns -1 if not supported by the system.

◆ getRudimentsVersion()

static const char* sys::getRudimentsVersion ( )
static

Returns the version of the rudiments library.

◆ getSignalsInterruptSystemCalls()

static bool sys::getSignalsInterruptSystemCalls ( )
static

Returns true if signals interrupt system calls on this platform and false if signals do not interrupt system calls.

◆ getSuggestedGroupEntryBufferSize()

static int64_t sys::getSuggestedGroupEntryBufferSize ( )
static

Returns a recommended buffer size, in bytes, for use by the getgrnam_r and getgrgid_r functions. This is used internally in the groupentry class if the system supports those functions. Returns -1 if not supported by the system.

◆ getSuggestedPasswordEntryBufferSize()

static int64_t sys::getSuggestedPasswordEntryBufferSize ( )
static

Returns a recommended buffer size, in bytes, for use by the getpwnam_r and getpwgid_r functions. This is used internally in the userentry class if the system supports those functions. Returns -1 if not supported by the system.

◆ getThreadDestructorIterations()

static int64_t sys::getThreadDestructorIterations ( )
static

Returns the number of tries that will be made to destroy thraed-specific data on thread exit. Returns -1 if not supported by the system.

◆ getUsedPhysicalMemorySize()

static int64_t sys::getUsedPhysicalMemorySize ( )
static

Returns the number of bytes of physical memory that are in use. Returns -1 if not supported by the system.

◆ getUsedPhysicalPageCount()

static int64_t sys::getUsedPhysicalPageCount ( )
static

Returns the number of pages of physical memory that are in use. Returns -1 if not supported by the system.

◆ halt()

static bool sys::halt ( )
static

Halts the operating system. The behavior of this command may vary between operating systems but it generally just halts the kernel without attempting to shut processes down gracefully or commit pending writes to storage.

◆ isBigEndian()

static bool sys::isBigEndian ( )
static

Returns true if the byte order of the system is big endian and false if the byte order of the system is little endian.

◆ reboot()

static bool sys::reboot ( )
static

Shuts down and restarts the machine. The behavior of this command may vary between operating systems. Particularly, many operating sytems execute a graceful shutdown before the restart, while others do not.

◆ setHostName() [1/2]

static bool sys::setHostName ( const char *  hostname)
static

Sets the host name of the machine, as understood by the kernel.

◆ setHostName() [2/2]

static bool sys::setHostName ( const char *  hostname,
uint64_t  hostnamelen 
)
static

Sets the host name of the machine, as understood by the kernel.

◆ setProtection()

static bool sys::setProtection ( byte_t *  ptr,
size_t  size,
int32_t  protection 
)
static

Sets the protection of the memory map to "protection" for "size" bytes, starting at "ptr".

"protection" may be: PROT_NONE - pages may not be accessed or an or'ed combination of the following: PROT_EXEC - pages may be excuted PROT_READ - pages may be read PROT_WRITE - pages may be written "protection" may not conflict with the open mode of the file. (eg. if the file was opened readonly then PROT_WRITE may not be used).

Note that not all filesystems support all of those options.

Returns true on success and false on failure.

◆ shutDown()

static bool sys::shutDown ( )
static

Shuts down the the machine. The behavior of this command may vary between operating systems but it generally attempts to shut processes down gracefully, commits pending writes to storage, halts the kernel and powers down the physical hardware.

◆ sync()

static void sys::sync ( )
static

Causes all pending writes to be committed to storage.

◆ sysConf()

static int64_t sys::sysConf ( int32_t  name)
static

Use the sysconf() system call directly to access values other than the ones provided above.