LLVM 22.0.0git
llvm::sys::Process Class Reference

A collection of legacy interfaces for querying information about the current executing process. More...

#include "llvm/Support/Process.h"

Public Types

using Pid = int32_t

Static Public Member Functions

static LLVM_ABI Pid getProcessId ()
 Get the process's identifier.
static LLVM_ABI Expected< unsignedgetPageSize ()
 Get the process's page size.
static unsigned getPageSizeEstimate ()
 Get the process's estimated page size.
static LLVM_ABI size_t GetMallocUsage ()
 Return process memory usage.
static LLVM_ABI void GetTimeUsage (TimePoint<> &elapsed, std::chrono::nanoseconds &user_time, std::chrono::nanoseconds &sys_time)
 This static function will set user_time to the amount of CPU time spent in user (non-kernel) mode and sys_time to the amount of CPU time spent in system (kernel) mode.
static LLVM_ABI void PreventCoreFiles ()
 This function makes the necessary calls to the operating system to prevent core files or any other kind of large memory dumps that can occur when a program fails.
static LLVM_ABI bool AreCoreFilesPrevented ()
 true if PreventCoreFiles has been called, false otherwise.
static LLVM_ABI std::optional< std::string > GetEnv (StringRef name)
static LLVM_ABI std::optional< std::string > FindInEnvPath (StringRef EnvName, StringRef FileName, ArrayRef< std::string > IgnoreList, char Separator=EnvPathSeparator)
 This function searches for an existing file in the list of directories in a PATH like environment variable, and returns the first file found, according to the order of the entries in the PATH like environment variable.
static LLVM_ABI std::optional< std::string > FindInEnvPath (StringRef EnvName, StringRef FileName, char Separator=EnvPathSeparator)
static LLVM_ABI std::error_code FixupStandardFileDescriptors ()
static LLVM_ABI std::error_code SafelyCloseFileDescriptor (int FD)
static LLVM_ABI bool StandardInIsUserInput ()
 This function determines if the standard input is connected directly to a user's input (keyboard probably), rather than coming from a file or pipe.
static LLVM_ABI bool StandardOutIsDisplayed ()
 This function determines if the standard output is connected to a "tty" or "console" window.
static LLVM_ABI bool StandardErrIsDisplayed ()
 This function determines if the standard error is connected to a "tty" or "console" window.
static LLVM_ABI bool FileDescriptorIsDisplayed (int fd)
 This function determines if the given file descriptor is connected to a "tty" or "console" window.
static LLVM_ABI bool FileDescriptorHasColors (int fd)
 This function determines if the given file descriptor is displayd and supports colors.
static LLVM_ABI unsigned StandardOutColumns ()
 This function determines the number of columns in the window if standard output is connected to a "tty" or "console" window.
static LLVM_ABI unsigned StandardErrColumns ()
 This function determines the number of columns in the window if standard error is connected to a "tty" or "console" window.
static LLVM_ABI bool StandardOutHasColors ()
 This function determines whether the terminal connected to standard output supports colors.
static LLVM_ABI bool StandardErrHasColors ()
 This function determines whether the terminal connected to standard error supports colors.
static LLVM_ABI void UseANSIEscapeCodes (bool enable)
 Enables or disables whether ANSI escape sequences are used to output colors.
static LLVM_ABI bool ColorNeedsFlush ()
 Whether changing colors requires the output to be flushed.
static LLVM_ABI const charOutputColor (char c, bool bold, bool bg)
 This function returns the colorcode escape sequences.
static LLVM_ABI const charOutputBold (bool bg)
 Same as OutputColor, but only enables the bold attribute.
static LLVM_ABI const charOutputReverse ()
 This function returns the escape sequence to reverse forground and background colors.
static LLVM_ABI const charResetColor ()
 Resets the terminals colors, or returns an escape sequence to do so.
static LLVM_ABI unsigned GetRandomNumber ()
 Get the result of a process wide random number generator.
static LLVM_ABI void Exit (int RetCode, bool NoCleanup=false)
 Equivalent to ::exit(), except when running inside a CrashRecoveryContext.

Detailed Description

A collection of legacy interfaces for querying information about the current executing process.

Definition at line 44 of file Process.h.

Member Typedef Documentation

◆ Pid

using llvm::sys::Process::Pid = int32_t

Definition at line 46 of file Process.h.

Member Function Documentation

◆ AreCoreFilesPrevented()

bool Process::AreCoreFilesPrevented ( )
static

true if PreventCoreFiles has been called, false otherwise.

Definition at line 108 of file Process.cpp.

References coreFilesPrevented.

◆ ColorNeedsFlush()

LLVM_ABI bool llvm::sys::Process::ColorNeedsFlush ( )
static

Whether changing colors requires the output to be flushed.

This is needed on systems that don't support escape sequences for changing colors.

References LLVM_ABI.

◆ Exit()

void Process::Exit ( int RetCode,
bool NoCleanup = false )
static

Equivalent to ::exit(), except when running inside a CrashRecoveryContext.

In that case, the control flow will resume after RunSafely(), like for a crash, rather than exiting the current process. Use

  • NoCleanup for calling _exit() instead of exit().

Definition at line 110 of file Process.cpp.

References llvm::CrashRecoveryContext::GetCurrent().

◆ FileDescriptorHasColors()

LLVM_ABI bool llvm::sys::Process::FileDescriptorHasColors ( int fd)
static

This function determines if the given file descriptor is displayd and supports colors.

References LLVM_ABI.

Referenced by llvm::raw_fd_ostream::has_colors().

◆ FileDescriptorIsDisplayed()

LLVM_ABI bool llvm::sys::Process::FileDescriptorIsDisplayed ( int fd)
static

This function determines if the given file descriptor is connected to a "tty" or "console" window.

That is, the output would be displayed to the user rather than being put on a pipe or stored in a file.

References LLVM_ABI.

Referenced by llvm::raw_fd_ostream::is_displayed().

◆ FindInEnvPath() [1/2]

std::optional< std::string > Process::FindInEnvPath ( StringRef EnvName,
StringRef FileName,
ArrayRef< std::string > IgnoreList,
char Separator = EnvPathSeparator )
static

This function searches for an existing file in the list of directories in a PATH like environment variable, and returns the first file found, according to the order of the entries in the PATH like environment variable.

If an ignore list is specified, then any folder which is in the PATH like environment variable but is also in IgnoreList is not considered.

Definition at line 39 of file Process.cpp.

References llvm::any_of(), llvm::sys::path::append(), assert(), llvm::sys::fs::equivalent(), llvm::sys::fs::exists(), GetEnv(), llvm::sys::path::is_absolute(), and llvm::SplitString().

Referenced by FindInEnvPath().

◆ FindInEnvPath() [2/2]

std::optional< std::string > Process::FindInEnvPath ( StringRef EnvName,
StringRef FileName,
char Separator = EnvPathSeparator )
static

Definition at line 34 of file Process.cpp.

References FindInEnvPath().

◆ FixupStandardFileDescriptors()

LLVM_ABI std::error_code llvm::sys::Process::FixupStandardFileDescriptors ( )
static

References LLVM_ABI.

◆ GetEnv()

◆ GetMallocUsage()

LLVM_ABI size_t llvm::sys::Process::GetMallocUsage ( )
static

Return process memory usage.

This static function will return the total amount of memory allocated by the process. This only counts the memory allocated via the malloc, calloc and realloc functions and includes any "free" holes in the allocated space.

References LLVM_ABI.

Referenced by getMemUsage().

◆ getPageSize()

LLVM_ABI Expected< unsigned > llvm::sys::Process::getPageSize ( )
static

Get the process's page size.

This may fail if the underlying syscall returns an error. In most cases, page size information is used for optimization, and this error can be safely discarded by calling consumeError, and an estimated page size substituted instead.

References LLVM_ABI.

Referenced by llvm::jitlink::InProcessMemoryManager::Create(), llvm::orc::InProcessMemoryMapper::Create(), llvm::orc::SelfExecutorProcessControl::Create(), llvm::orc::SharedMemoryMapper::Create(), and getPageSizeEstimate().

◆ getPageSizeEstimate()

unsigned llvm::sys::Process::getPageSizeEstimate ( )
inlinestatic

Get the process's estimated page size.

This function always succeeds, but if the underlying syscall to determine the page size fails then this will silently return an estimated page size. The estimated page size is guaranteed to be a power of 2.

Definition at line 62 of file Process.h.

References llvm::consumeError(), getPageSize(), and PageSize.

Referenced by llvm::orc::ELFDebugObject::finalizeWorkingMemory(), getOpenFileImpl(), llvm::orc::SelfExecutorProcessControl::SelfExecutorProcessControl(), and llvm::trimBlockToPageSize().

◆ getProcessId()

LLVM_ABI Pid llvm::sys::Process::getProcessId ( )
static

◆ GetRandomNumber()

LLVM_ABI unsigned llvm::sys::Process::GetRandomNumber ( )
static

Get the result of a process wide random number generator.

The generator will be automatically seeded in non-deterministic fashion.

References LLVM_ABI.

Referenced by llvm::sys::fs::createUniquePath().

◆ GetTimeUsage()

LLVM_ABI void llvm::sys::Process::GetTimeUsage ( TimePoint<> & elapsed,
std::chrono::nanoseconds & user_time,
std::chrono::nanoseconds & sys_time )
static

This static function will set user_time to the amount of CPU time spent in user (non-kernel) mode and sys_time to the amount of CPU time spent in system (kernel) mode.

If the operating system does not support collection of these metrics, a zero duration will be for both values.

Parameters
elapsedReturns the system_clock::now() giving current time
user_timeReturns the current amount of user time for the process
sys_timeReturns the current amount of system time for the process

References LLVM_ABI.

Referenced by llvm::TimeRecord::getCurrentTime().

◆ OutputBold()

LLVM_ABI const char * llvm::sys::Process::OutputBold ( bool bg)
static

Same as OutputColor, but only enables the bold attribute.

References LLVM_ABI.

Referenced by llvm::raw_ostream::changeColor().

◆ OutputColor()

LLVM_ABI const char * llvm::sys::Process::OutputColor ( char c,
bool bold,
bool bg )
static

This function returns the colorcode escape sequences.

If ColorNeedsFlush() is true then this function will change the colors and return an empty escape sequence. In that case it is the responsibility of the client to flush the output stream prior to calling this function.

References LLVM_ABI.

Referenced by llvm::raw_ostream::changeColor().

◆ OutputReverse()

LLVM_ABI const char * llvm::sys::Process::OutputReverse ( )
static

This function returns the escape sequence to reverse forground and background colors.

References LLVM_ABI.

Referenced by llvm::raw_ostream::reverseColor().

◆ PreventCoreFiles()

LLVM_ABI void llvm::sys::Process::PreventCoreFiles ( )
static

This function makes the necessary calls to the operating system to prevent core files or any other kind of large memory dumps that can occur when a program fails.

Prevent core file generation.

References LLVM_ABI.

◆ ResetColor()

LLVM_ABI const char * llvm::sys::Process::ResetColor ( )
static

Resets the terminals colors, or returns an escape sequence to do so.

References LLVM_ABI.

Referenced by llvm::raw_ostream::resetColor().

◆ SafelyCloseFileDescriptor()

LLVM_ABI std::error_code llvm::sys::Process::SafelyCloseFileDescriptor ( int FD)
static

◆ StandardErrColumns()

LLVM_ABI unsigned llvm::sys::Process::StandardErrColumns ( )
static

This function determines the number of columns in the window if standard error is connected to a "tty" or "console" window.

If standard error is not connected to a tty or console, or if the number of columns cannot be determined, this routine returns zero.

References LLVM_ABI.

◆ StandardErrHasColors()

LLVM_ABI bool llvm::sys::Process::StandardErrHasColors ( )
static

This function determines whether the terminal connected to standard error supports colors.

If standard error is not connected to a terminal, this function returns false.

References LLVM_ABI.

◆ StandardErrIsDisplayed()

LLVM_ABI bool llvm::sys::Process::StandardErrIsDisplayed ( )
static

This function determines if the standard error is connected to a "tty" or "console" window.

That is, the output would be displayed to the user rather than being put on a pipe or stored in a file.

References LLVM_ABI.

◆ StandardInIsUserInput()

LLVM_ABI bool llvm::sys::Process::StandardInIsUserInput ( )
static

This function determines if the standard input is connected directly to a user's input (keyboard probably), rather than coming from a file or pipe.

References LLVM_ABI.

◆ StandardOutColumns()

LLVM_ABI unsigned llvm::sys::Process::StandardOutColumns ( )
static

This function determines the number of columns in the window if standard output is connected to a "tty" or "console" window.

If standard output is not connected to a tty or console, or if the number of columns cannot be determined, this routine returns zero.

References LLVM_ABI.

◆ StandardOutHasColors()

LLVM_ABI bool llvm::sys::Process::StandardOutHasColors ( )
static

This function determines whether the terminal connected to standard output supports colors.

If standard output is not connected to a terminal, this function returns false.

References LLVM_ABI.

◆ StandardOutIsDisplayed()

LLVM_ABI bool llvm::sys::Process::StandardOutIsDisplayed ( )
static

This function determines if the standard output is connected to a "tty" or "console" window.

That is, the output would be displayed to the user rather than being put on a pipe or stored in a file.

References LLVM_ABI.

◆ UseANSIEscapeCodes()

LLVM_ABI void llvm::sys::Process::UseANSIEscapeCodes ( bool enable)
static

Enables or disables whether ANSI escape sequences are used to output colors.

This only has an effect on Windows. Note: Setting this option is not thread-safe and should only be done during initialization.

References LLVM_ABI.


The documentation for this class was generated from the following files: