NCBI C++ ToolKit
|
Classes | |
class | CInterProcessLock |
CInterProcessLock –. More... | |
class | PInterProcessLock |
class | CInterProcessLockException |
CInterProcessLockException –. More... | |
class | CProcessBase |
CProcessBase –. More... | |
struct | CProcessBase::SMemoryUsage |
Process memory usage information, in bytes. More... | |
class | CCurrentProcess |
CCurrentProcess –. More... | |
class | CProcess |
CProcess –. More... | |
class | CProcess::CExitInfo |
Extended exit information for waited process. More... | |
class | CPIDGuardException |
CPIDGuardException –. More... | |
class | CPIDGuard |
CPIDGuard – Process guard. More... | |
Typedefs | |
typedef int | CInterProcessLock::TLockHandle |
OS-specific lock handle. More... | |
typedef CInterProcessLock | PInterProcessLock::resource_type |
typedef CGuard< CInterProcessLock, PInterProcessLock > | CInterProcessLock_Guard |
Convenience typedef for PInterProcessLock. More... | |
typedef pid_t | TPid |
Process identifier (PID) and process handle. More... | |
typedef TPid | TProcessHandle |
typedef unsigned | CCurrentProcess::TForkFlags |
Bit-wise OR of FForkFlags. More... | |
typedef unsigned int | CCurrentProcess::TDaemonFlags |
Bit-wise OR of FDaemonFlags. More... | |
typedef unsigned | CProcess::TForkFlags |
Bit-wise OR of FForkFlags. More... | |
typedef unsigned int | CProcess::TDaemonFlags |
Bit-wise OR of FDaemonFlags. More... | |
Functions | |
CInterProcessLock::CInterProcessLock (const string &name) | |
CInterProcessLock::~CInterProcessLock (void) | |
Call Unlock() More... | |
bool | CInterProcessLock::TryLock (void) |
Try to acquire the lock. More... | |
void | CInterProcessLock::Remove (void) |
Call Unlock() and removes lock object from the system. More... | |
const string & | CInterProcessLock::GetName (void) const |
Get the original name of the lock – exactly as it was specified in the constructor. More... | |
const string & | CInterProcessLock::GetSystemName (void) const |
Get the internal name of the lock – as it is being used in the calls to the OS (such as '/var/tmp/<name>' rather than just '<name>' on UNIX) More... | |
PInterProcessLock::PInterProcessLock (const CTimeout &timeout, const CTimeout &granularity=CTimeout(CTimeout::eInfinite)) | |
void | PInterProcessLock::operator() (resource_type &resource) const |
virtual const char * | CInterProcessLockException::GetErrCodeString (void) const override |
Translate from an error code value to its string representation. More... | |
CInterProcessLockException::NCBI_EXCEPTION_DEFAULT (CInterProcessLockException, CCoreException) | |
static TProcessHandle | CCurrentProcess::GetHandle (void) |
Get process handle for the current process (esp. More... | |
static TPid | CCurrentProcess::GetPid (void) |
Get process identifier (pid) for the current process. More... | |
static TPid | CCurrentProcess::GetParentPid (void) |
Get process identifier (pid) for the parent of the current process. More... | |
static bool | CCurrentProcess::GetTimes (double *real, double *user, double *sys, EWhat what=eProcess) |
Get current process execution times. More... | |
static bool | CCurrentProcess::GetMemoryUsage (SMemoryUsage &usage) |
Get current process memory usage. More... | |
static int | CCurrentProcess::GetThreadCount (void) |
Get the number of threads in the current process. More... | |
static int | CCurrentProcess::GetFileDescriptorsCount (int *soft_limit=NULL, int *hard_limit=NULL) |
Get the number of file descriptors consumed by the current process, and optional system wide file descriptor limits. More... | |
static TPid | CCurrentProcess::Fork (TForkFlags flags=fFF_UpdateDiag) |
Fork the process. More... | |
static TPid | CCurrentProcess::ForkForExec (TForkFlags flags=0) |
Fork the process for "replacing" a child process with a new process. More... | |
static TPid | CCurrentProcess::Daemonize (const char *logfile=0, TDaemonFlags flags=0) |
Go daemon. More... | |
CProcess::CProcess (void) | |
Default constructor. Uses the current process pid. More... | |
CProcess::CProcess (TPid process, EType type=eHandle) | |
Constructor. More... | |
EType | CProcess::GetType (void) const |
Get type of stored process identifier. More... | |
TProcessHandle | CProcess::GetHandle (void) const |
Get stored process handle. More... | |
TPid | CProcess::GetPid (void) const |
Get stored process identifier (pid). More... | |
bool | CProcess::IsCurrent (void) |
Checks that stored process identifier (pid) represent the current process. More... | |
bool | CProcess::IsAlive (void) const |
Check for process existence. More... | |
bool | CProcess::Kill (unsigned long timeout=kDefaultKillTimeout) |
Terminate process. More... | |
bool | CProcess::KillGroup (unsigned long timeout=kDefaultKillTimeout) const |
Terminate a group of processes. More... | |
static bool | CProcess::KillGroupById (TPid pgid, unsigned long timeout=kDefaultKillTimeout) |
Terminate a group of processes with specified ID. More... | |
CProcess::CExitInfo::CExitInfo (void) | |
Constructor. More... | |
bool | CProcess::CExitInfo::IsPresent (void) const |
TRUE if the object contains information about the process state. More... | |
bool | CProcess::CExitInfo::IsAlive (void) const |
TRUE if the process is still alive. More... | |
bool | CProcess::CExitInfo::IsExited (void) const |
TRUE if the process terminated normally. More... | |
bool | CProcess::CExitInfo::IsSignaled (void) const |
TRUE if the process terminated by a signal (UNIX only). More... | |
int | CProcess::CExitInfo::GetExitCode (void) const |
Get process exit code. More... | |
int | CProcess::CExitInfo::GetSignal (void) const |
Get the signal number that has caused the process to terminate (UNIX only). More... | |
int | CProcess::Wait (unsigned long timeout=kInfiniteTimeoutMs, CExitInfo *info=0) const |
Wait until process terminates. More... | |
int | CProcess::WaitTimeout (unsigned long timeout, CExitInfo *info=0) const |
Wait until the process terminates or timeout expires. More... | |
int | CProcess::WaitInfinite (CExitInfo *info=0) const |
Wait indefinitely until the process terminates. More... | |
static TProcessHandle | CProcess::GetCurrentHandle (void) |
static TPid | CProcess::GetCurrentPid (void) |
static TPid | CProcess::GetParentPid (void) |
bool | CProcess::GetTimes (double *real, double *user, double *sys, EWhat what=eProcess) |
Get process execution times. More... | |
bool | CProcess::GetMemoryUsage (SMemoryUsage &usage) |
Get process memory usage. More... | |
int | CProcess::GetThreadCount (void) |
Get the number of threads in the process. More... | |
int | CProcess::GetFileDescriptorsCount (void) |
Get the number of file descriptors consumed by the current process. More... | |
static TPid | CProcess::Fork (TForkFlags flags=fFF_UpdateDiag) |
Fork the process. More... | |
static TPid | CProcess::Daemonize (const char *logfile=0, TDaemonFlags flags=0) |
Go daemon. More... | |
TPid | CProcess::x_GetPid (void) const |
TProcessHandle | CProcess::x_GetHandle (DWORD desired_access, DWORD *errcode=0) const |
void | CProcess::x_CloseHandle (TProcessHandle handle) const |
virtual const char * | CPIDGuardException::GetErrCodeString (void) const override |
virtual void | CPIDGuardException::ReportExtra (ostream &out) const override |
Constructor. More... | |
TPid | CPIDGuardException::GetPID (void) const throw () |
virtual void | CPIDGuardException::x_Assign (const CException &src) override |
CPIDGuard::CPIDGuard (const string &filename) | |
Create/check PID file. More... | |
CPIDGuard::CPIDGuard (const string &filename, const string &dir) | |
Create/check PID file. More... | |
CPIDGuard::~CPIDGuard (void) | |
Destructor. More... | |
void | CPIDGuard::Release (void) |
Release PID. More... | |
void | CPIDGuard::Remove (void) |
Remove the file. More... | |
void | CPIDGuard::UpdatePID (TPid pid=0) |
Update PID in the file. More... | |
TPid | CPIDGuard::GetOldPID (void) |
Returns non-zero if there was a stale file. More... | |
Friends | |||||
class | CProcess::CExitInfo::CProcess | ||||
Lock/guard interface (to use with CGuard<> or CInterProcessLock_Guard) Try to acquire the lock. On any error, or if the lock is already held by another process and it could not be acquired within the allotted time period, throw CInterProcessLockException.
| |||||
void | CInterProcessLock::Lock (const CTimeout &timeout=CTimeout(CTimeout::eInfinite), const CTimeout &granularity=CTimeout(CTimeout::eInfinite)) | ||||
void | CInterProcessLock::Unlock (void) | ||||
Release the lock. More... | |||||
Convenience typedef for PInterProcessLock.
Definition at line 231 of file interprocess_lock.hpp.
Definition at line 209 of file interprocess_lock.hpp.
typedef unsigned int CCurrentProcess::TDaemonFlags |
typedef unsigned int CProcess::TDaemonFlags |
Bit-wise OR of FDaemonFlags.
Definition at line 749 of file ncbi_process.hpp.
typedef unsigned CCurrentProcess::TForkFlags |
typedef unsigned CProcess::TForkFlags |
Bit-wise OR of FForkFlags.
Definition at line 721 of file ncbi_process.hpp.
|
private |
OS-specific lock handle.
Definition at line 185 of file interprocess_lock.hpp.
typedef pid_t TPid |
Process identifier (PID) and process handle.
Definition at line 77 of file ncbi_process.hpp.
typedef TPid TProcessHandle |
Definition at line 78 of file ncbi_process.hpp.
Error types that file operations can generate.
Definition at line 244 of file interprocess_lock.hpp.
Enumerator | |
---|---|
eStillRunning | The process listed in the file is still around. |
eWrite | Unable to write into the PID file. |
Definition at line 811 of file ncbi_process.hpp.
enum CProcess::EType |
How to interpret the used process identifier.
Enumerator | |
---|---|
ePid | A real process identifier (pid). |
eHandle | A process handle (MS Windows). |
Definition at line 392 of file ncbi_process.hpp.
enum CProcessBase::EWhat |
Process information "target".
Enumerator | |
---|---|
eProcess | Current process. |
eChildren | All children of the calling process. |
eThread | Current thread. |
Definition at line 100 of file ncbi_process.hpp.
Daemonization flags.
Definition at line 318 of file ncbi_process.hpp.
Daemonization flags @ deprecated Please use CCurrentProcess::FDaemonFlags instead.
Enumerator | |
---|---|
fDF_KeepCWD | |
fDF_KeepStdin | |
fDF_KeepStdout | |
fDF_ImmuneTTY | |
fDF_KeepParent | |
fDF_AllowExceptions | |
fDF_AllowThreads | |
fDontChroot | |
fKeepStdin | |
fKeepStdout | |
fImmuneTTY | |
fKeepParent |
Definition at line 732 of file ncbi_process.hpp.
Forking flags.
Definition at line 255 of file ncbi_process.hpp.
enum CProcess::FForkFlags |
Forking flags.
@ deprecated Please use CCurrentProcess::FForkFlags instead
Enumerator | |
---|---|
fFF_UpdateDiag | |
fFF_AllowExceptions |
Definition at line 715 of file ncbi_process.hpp.
CProcess::CExitInfo::CExitInfo | ( | void | ) |
Constructor.
Definition at line 113 of file ncbi_process.cpp.
References eExitInfo_Unknown, and CProcess::CExitInfo::status.
name | Name of the lock. The name must be a Unix-path like, and its length must not exceed the maximum path length that is specific for the OS where the application runs. |
Definition at line 72 of file interprocess_lock.cpp.
References CDirEntry::IsAbsolutePath(), kInvalidLockHandle, CInterProcessLock::m_Handle, CInterProcessLock::m_Name, CInterProcessLock::m_SystemName, NCBI_THROW, NPOS, PATH_MAX, and NStr::Replace().
Create/check PID file.
If the file already exists and identifies a live process, throws CPIDGuardException.
filename | Name of the file to store PID. If "filename" contains path, it should be absolute and points to an existing directory. If "filename" contains no path, that $TMPDIR will be used on Unix, and HOME% on Windows to store it. |
Definition at line 1720 of file ncbi_process.cpp.
References CDir::GetTmpDir(), CPIDGuard::m_MTGuard, CPIDGuard::m_Path, CDirEntry::MakePath(), CDirEntry::SplitPath(), and CPIDGuard::UpdatePID().
Create/check PID file.
If the file already exists and identifies a live process, throws CPIDGuardException.
filename | Name of the file to store PID. If should not include any path, relative or absolute. |
dir | An absolute path to the existing directory on the file system to store PID file "filename". If "dir" is empty and "filename" contains no path, that $TMPDIR will be used on Unix, and HOME% on Windows to store it. |
Definition at line 1738 of file ncbi_process.cpp.
References CDir::GetTmpDir(), CPIDGuard::m_MTGuard, CPIDGuard::m_Path, CDirEntry::MakePath(), CDirEntry::SplitPath(), and CPIDGuard::UpdatePID().
Constructor.
Definition at line 525 of file ncbi_process.cpp.
CProcess::CProcess | ( | void | ) |
Default constructor. Uses the current process pid.
Definition at line 516 of file ncbi_process.cpp.
|
static |
Go daemon.
Return TPid(-1) in the daemon thread (the parent thread doesn't return unless fKeepParent is set), or TPid(daemon) in the parent thread. On error return 0 in the parent thread (no daemon created), see errno.
Reopen stderr/cerr in the daemon thread if "logfile" specified as non-NULL (stderr will open to "/dev/null" if "logfile" has been passed as ""), otherwise stderr is closed in the daemon thread.
Unless instructed by the "flags" parameter, the daemon thread has its stdin/cin and stdout/cout closed, and the current working directory changed to the root directory ("/").
If kept open, stdin and stdout are both redirected to "/dev/null". Opening a terminal device as a controlling terminal is allowed, unless fImmuneTTY is specified in the flags, which then causes a second fork() so that the resultant process won't be allowed to open a TTY as its controlling TTY (but only with an explicit O_NOCTTY, see open(2)), thus protecting the process from any blocking via TTY signaling.
Note that this call is somewhat destructive and may not be able to restore the process that called it to a state prior to the call in case of an error. So that calling process can find the standard
Definition at line 485 of file ncbi_process.cpp.
References ERR_POST_X, CCurrentProcess::fDF_AllowExceptions, flags, NCBI_THROW, s_Daemonize(), and CException::what().
Referenced by CProcess::Daemonize(), SGridWorkerNodeImpl::Run(), CBDBEnvKeeperApp::Run(), CNetScheduleDApp::Run(), CNetStorageDApp::Run(), and CPubseqGatewayApp::Run().
|
inlinestatic |
Go daemon.
Return TPid(-1) in the daemon thread (the parent thread doesn't return unless fKeepParent is set), or TPid(daemon) in the parent thread. On error return 0 in the parent thread (no daemon created), see errno.
Reopen stderr/cerr in the daemon thread if "logfile" specified as non-NULL (stderr will open to "/dev/null" if "logfile" has been passed as ""), otherwise stderr is closed in the daemon thread.
Unless instructed by the "flags" parameter, the daemon thread has its stdin/cin and stdout/cout closed, and the current working directory changed to the root directory ("/").
If kept open, stdin and stdout are both redirected to "/dev/null". Opening a terminal device as a controlling terminal is allowed, unless fImmuneTTY is specified in the flags, which then causes a second fork() so that the resultant process won't be allowed to open a TTY as its controlling TTY (but only with an explicit O_NOCTTY, see open(2)), thus protecting the process from any blocking via TTY signaling.
Note that this call is somewhat destructive and may not be able to restore the process that called it to a state prior to the call in case of an error. So that calling process can find the standard
Definition at line 778 of file ncbi_process.hpp.
References CCurrentProcess::Daemonize(), and flags.
Referenced by Daemonize(), and main().
|
static |
Fork the process.
Update PID and GUID used for logging (by default).
If | the fFF_AllowExceptions flag is specified, throws a CCoreException in case of a fork(2) failure. If the platform does not support process forking, an exception is always thrown regardless of whether the fFF_AllowExceptions flag is specified. |
Definition at line 308 of file ncbi_process.cpp.
References ERR_POST_X, f(), CProcess::fFF_AllowExceptions, CProcess::fFF_UpdateDiag, flags, CDiagContext::fOnFork_AsyncSafe, CDiagContext::fOnFork_PrintStart, CDiagContext::fOnFork_ResetTimer, CCurrentProcess::GetThreadCount(), NCBI_THROW, NCBI_THROW_FMT, s_ErrnoToString(), CDiagContext::UpdateOnFork(), and Warning().
Referenced by CProcess::Fork(), CCurrentProcess::ForkForExec(), SGridWorkerNodeImpl::Run(), and s_Daemonize().
|
inlinestatic |
Fork the process.
Definition at line 726 of file ncbi_process.hpp.
References flags, and CCurrentProcess::Fork().
|
inlinestatic |
Fork the process for "replacing" a child process with a new process.
Special version of Fork() with a different name for easier recognizing. Assumes that the user will replace child process after this call with using exec(3) or execve(2) calls as soon as possible. The child can safely call only async-signal-safe functions after Fork() until the child process has replaced. This mean no memory allocation, streams, logging and etc. Please consult the list of sync-signal-safe functions before using, like: https://man7.org/linux/man-pages/man7/signal-safety.7.html
Definition at line 315 of file ncbi_process.hpp.
References CCurrentProcess::fFF_Exec, flags, and CCurrentProcess::Fork().
|
inlinestatic |
Definition at line 605 of file ncbi_process.hpp.
References CCurrentProcess::GetHandle().
Definition at line 611 of file ncbi_process.hpp.
References CCurrentProcess::GetPid().
|
overridevirtual |
Translate from an error code value to its string representation.
Reimplemented from CCoreException.
Definition at line 400 of file interprocess_lock.cpp.
References CInterProcessLockException::eCreateError, CInterProcessLockException::eLockError, CInterProcessLockException::eLockTimeout, CInterProcessLockException::eMultipleLocks, CInterProcessLockException::eNotLocked, CInterProcessLockException::eUnlockError, CCoreException::GetErrCode(), and CException::GetErrCodeString().
|
overridevirtual |
Definition at line 1901 of file ncbi_process.cpp.
References CPIDGuardException::eStillRunning, CPIDGuardException::eWrite, and CException::GetErrCodeString().
int CProcess::CExitInfo::GetExitCode | ( | void | ) | const |
Get process exit code.
Works only if IsExited() returns TRUE, otherwise returns -1.
Definition at line 163 of file ncbi_process.cpp.
Referenced by SGridWorkerNodeImpl::Run(), s_Close(), s_GetBigBedFeats(), s_GetBigBedSummary(), s_GetData(), CBLASTSeqToolJob::x_CreateProjectItems(), and CWigGraph::x_RunBigWigScript().
|
static |
Get the number of file descriptors consumed by the current process, and optional system wide file descriptor limits.
soft_limit | Pointer to a variable that receives system wide soft limit. -1 means it was impossible to get the limit. |
hard_limit | Pointer to a variable that receives system wide hard limit. -1 means it was impossible to get the limit. |
Definition at line 1659 of file ncbi_process.cpp.
References CNcbiError::eNotSupported, CNcbiError::eUnknown, CCurrentProcess::GetPid(), n, and CNcbiError::Set().
Referenced by CheckFDLimit(), CProcess::GetFileDescriptorsCount(), CPubseqGatewayApp::OnInfo(), and CNetScheduleHandler::x_ProcessHealth().
int CProcess::GetFileDescriptorsCount | ( | void | ) |
Get the number of file descriptors consumed by the current process.
For current process pid/handle it is the same as CCurrentProcess::GetFileDescriptorsCount().
Definition at line 1643 of file ncbi_process.cpp.
References CNcbiError::eNotSupported, CCurrentProcess::GetFileDescriptorsCount(), CProcess::GetPid(), CProcess::IsCurrent(), and CNcbiError::Set().
|
static |
Get process handle for the current process (esp.
on Windows).
Definition at line 237 of file ncbi_process.cpp.
References CProcess::GetPid().
Referenced by CProcess::GetCurrentHandle(), CProcess::IsCurrent(), and CTar::x_Append().
|
inline |
Get stored process handle.
Definition at line 419 of file ncbi_process.hpp.
References CProcess::m_Process.
Referenced by CProcess::IsCurrent(), CRemoteAppReaperTask::operator()(), CProcess::x_GetHandle(), and CProcess::x_GetPid().
|
static |
Get current process memory usage.
Definition at line 1474 of file ncbi_process.cpp.
References _TROUBLE, CNcbiError::eNotSupported, CNcbiError::eUnknown, CFile::GetLength(), GetMemoryUsage(), len, s_Win_GetMemoryUsage(), CNcbiError::Set(), CNcbiError::SetFromErrno(), and usage.
Referenced by CCgiApplication::CheckMemoryLimit(), CProcess::GetMemoryUsage(), CWNJobWatcher::Notify(), CPubseqGatewayApp::OnInfo(), ReportMemoryUsage(), CAsnSubCacheCreateApplication::Run(), CAlignSort::SortAlignments(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
bool CProcess::GetMemoryUsage | ( | SMemoryUsage & | usage | ) |
Get process memory usage.
For current process pid/handle it is the same as CCurrentProcess::GetMemoryUsage().
usage | Total memory usage by a process, in bytes. See SMemoryUsage structure. |
resident | Resident set size (RSS), in bytes. RSS is the portion of memory occupied by a process that is held in main memory (RAM). |
shared | (optional) Shared memory usage, in bytes. |
data | (optional) Data + stack usage, in bytes. |
Definition at line 1445 of file ncbi_process.cpp.
References CNcbiError::eNotSupported, GetMemoryUsage(), CCurrentProcess::GetMemoryUsage(), CProcess::GetPid(), HANDLE, CProcess::IsCurrent(), s_Win_GetMemoryUsage(), CNcbiError::Set(), usage, CProcess::x_CloseHandle(), and CProcess::x_GetHandle().
Get the original name of the lock – exactly as it was specified in the constructor.
Definition at line 171 of file interprocess_lock.hpp.
References CInterProcessLock::m_Name.
|
inline |
Returns non-zero if there was a stale file.
Always return 0, because new implementation don't allow any stale file left on the file system.
Definition at line 928 of file ncbi_process.hpp.
|
static |
Get process identifier (pid) for the parent of the current process.
Definition at line 259 of file ncbi_process.cpp.
References CWinFeature::FindProcessEntry(), and CNcbiError::SetFromWindowsError().
Referenced by CProcess::GetParentPid().
Definition at line 617 of file ncbi_process.hpp.
References CCurrentProcess::GetParentPid().
|
static |
Get process identifier (pid) for the current process.
Definition at line 247 of file ncbi_process.cpp.
Referenced by CDbapiSampleApp::CDbapiSampleApp(), CMessageDumperSender::CMessageDumperSender(), CFileIO::CreateTemporary(), CRtProfiler::DoReport(), CProcess::GetCurrentPid(), CAppExplorerDataObject::GetDataHere(), CCgiApplication::GetFastCGIWatchFileRestartDelay(), CCurrentProcess::GetFileDescriptorsCount(), CDiagContext::GetPID(), TDataExchange< T >::Init(), CProcess::IsCurrent(), TDataExchange< T >::IsLocal(), SProjectSelectorParams::LoadSettings(), CBDB_Cache::Open(), CNCStat::PrintToSocket(), CGetStatisticsProcessor::Process(), CRandom::Randomize(), SGridWorkerNodeImpl::Run(), CThreadedApp::Run(), s_GenerateSessionTag(), s_InitConstants(), s_LockInstanceGuard(), s_ReportPid(), SProjectSelectorParams::SaveSettings(), CAppExplorerDataObject::SetData(), CPIDGuard::UpdatePID(), CDiagContext::UpdatePID_AsyncSafe(), CNCServer::WriteEnvInfo(), CNetScheduleServer::x_GenerateGUID(), CNetStorageServer::x_GenerateGUID(), CAgpFastaComparator::CTmpSeqVecStorage::x_GetTmpDir(), CWNJobWatcher::x_KillNode(), and CFastCgiApplicationMT::x_ProcessThreadedRequest().
|
inline |
Get stored process identifier (pid).
Definition at line 424 of file ncbi_process.hpp.
References CProcess::m_Process.
Referenced by CProcess::GetFileDescriptorsCount(), CCurrentProcess::GetHandle(), CProcess::GetMemoryUsage(), CProcess::GetThreadCount(), CProcess::GetTimes(), CProcess::IsAlive(), CProcess::IsCurrent(), CProcess::Kill(), CProcess::KillGroup(), CProcess::Wait(), CProcess::x_GetHandle(), and CProcess::x_GetPid().
|
inline |
Definition at line 833 of file ncbi_process.hpp.
References CPIDGuardException::m_PID.
int CProcess::CExitInfo::GetSignal | ( | void | ) | const |
Get the signal number that has caused the process to terminate (UNIX only).
Works only if IsSignaled() returns TRUE, otherwise returns -1.
Definition at line 176 of file ncbi_process.cpp.
Referenced by SGridWorkerNodeImpl::Run(), s_Close(), and CWigGraph::x_RunBigWigScript().
Get the internal name of the lock – as it is being used in the calls to the OS (such as '/var/tmp/<name>' rather than just '<name>' on UNIX)
Definition at line 175 of file interprocess_lock.hpp.
References CInterProcessLock::m_SystemName.
|
static |
Get the number of threads in the current process.
Definition at line 1624 of file ncbi_process.cpp.
References CNcbiError::eNotSupported, CWinFeature::FindProcessEntry(), CNcbiError::Set(), and CNcbiError::SetFromWindowsError().
Referenced by CCurrentProcess::Fork(), CPubseqGatewayApp::OnInfo(), and CNetScheduleHandler::x_ProcessHealth().
int CProcess::GetThreadCount | ( | void | ) |
Get the number of threads in the process.
For current process pid/handle it is the same as CCurrentProcess::GetThreadCount().
Definition at line 1605 of file ncbi_process.cpp.
References CNcbiError::eNotSupported, CWinFeature::FindProcessEntry(), CProcess::GetPid(), CNcbiError::Set(), CNcbiError::SetFromWindowsError(), and CProcess::x_GetPid().
|
static |
Get current process execution times.
real | Pointer to a variable that receives the amount of time in second that the current process/thread has executed, when available. |
user | Pointer to a variable that receives the amount of time in seconds that the process, process tree or thread has executed in user mode. Note, that this value can exceed the amount of "real" time if the process executes across multiple CPU cores (OS dependent). |
sys | Pointer to a variable that receives the amount of time in second that the current process, process tree or thread has executed in kernel mode. |
what | Applies to user and system time parameters only, real time calculates for the current process only. Defines what times to measure: current thread, process or children processes:
|
Definition at line 1276 of file ncbi_process.cpp.
References _TROUBLE, buf, CProcessBase::eChildren, CNcbiError::eNotSupported, CProcessBase::eProcess, CProcessBase::eThread, CSystemInfo::GetClockTicksPerSecond(), kUndefined, s_Win_GetHandleTimes(), CNcbiError::Set(), CNcbiError::SetFromErrno(), and t.
Referenced by CProcess::GetTimes(), CPubseqGatewayApp::OnInfo(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
bool CProcess::GetTimes | ( | double * | real, |
double * | user, | ||
double * | sys, | ||
CProcess::EWhat | what = eProcess |
||
) |
Get process execution times.
For current process pid/handle it is the same as CCurrentProcess::GetTimes().
real | Pointer to a variable that receives the amount of time in second that the process/thread has executed, when available. |
user | Pointer to a variable that receives the amount of time in seconds that the process, process tree or thread has executed in user mode. Note, that this value can exceed the amount of "real" time if the process executes across multiple CPU cores (OS dependent). |
sys | Pointer to a variable that receives the amount of time in second that the current process, process tree or thread has executed in kernel mode. |
what | Defines what times to measure: current thread, process or children processes:
|
Definition at line 1225 of file ncbi_process.cpp.
References CProcessBase::eChildren, CNcbiError::eNotSupported, CProcessBase::eProcess, CProcessBase::eThread, CProcess::GetPid(), CCurrentProcess::GetTimes(), HANDLE, CProcess::IsCurrent(), kUndefined, s_Win_GetHandleTimes(), CNcbiError::Set(), CProcess::x_CloseHandle(), and CProcess::x_GetHandle().
|
inline |
Get type of stored process identifier.
Definition at line 414 of file ncbi_process.hpp.
References CProcess::m_Type.
Referenced by CProcess::IsCurrent(), CProcess::Kill(), CProcess::x_CloseHandle(), CProcess::x_GetHandle(), and CProcess::x_GetPid().
bool CProcess::IsAlive | ( | void | ) | const |
Check for process existence.
Definition at line 609 of file ncbi_process.cpp.
References _ASSERT, CProcess::GetPid(), HANDLE, CProcess::x_CloseHandle(), and CProcess::x_GetHandle().
Referenced by CProcess::Kill(), and CBamLoadingJob::x_CreateDataLoader().
bool CProcess::CExitInfo::IsAlive | ( | void | ) | const |
TRUE if the process is still alive.
Definition at line 126 of file ncbi_process.cpp.
References eExitInfo_Alive, and EXIT_INFO_CHECK.
Referenced by s_Close().
bool CProcess::IsCurrent | ( | void | ) |
Checks that stored process identifier (pid) represent the current process.
Definition at line 589 of file ncbi_process.cpp.
References CProcess::eHandle, CProcess::ePid, eTriState_False, eTriState_True, CCurrentProcess::GetHandle(), CProcess::GetHandle(), CCurrentProcess::GetPid(), CProcess::GetPid(), CProcess::GetType(), and CProcess::m_IsCurrent.
Referenced by CProcess::GetFileDescriptorsCount(), CProcess::GetMemoryUsage(), CProcess::GetTimes(), and CProcess::Kill().
bool CProcess::CExitInfo::IsExited | ( | void | ) | const |
TRUE if the process terminated normally.
Definition at line 133 of file ncbi_process.cpp.
References eExitInfo_Terminated, and EXIT_INFO_CHECK.
Referenced by CRemoteAppReaperTask::operator()(), SGridWorkerNodeImpl::Run(), and s_Close().
bool CProcess::CExitInfo::IsPresent | ( | void | ) | const |
TRUE if the object contains information about the process state.
All other methods' return values are good only if this method returns TRUE, otherwise they may throw exceptions.
Definition at line 120 of file ncbi_process.cpp.
References eExitInfo_Unknown.
Referenced by SGridWorkerNodeImpl::Run(), and s_Close().
bool CProcess::CExitInfo::IsSignaled | ( | void | ) | const |
TRUE if the process terminated by a signal (UNIX only).
Definition at line 148 of file ncbi_process.cpp.
References eExitInfo_Terminated, and EXIT_INFO_CHECK.
Referenced by CRemoteAppReaperTask::operator()(), SGridWorkerNodeImpl::Run(), s_Close(), and CWigGraph::x_RunBigWigScript().
bool CProcess::Kill | ( | unsigned long | timeout = kDefaultKillTimeout | ) |
Terminate process.
First try "soft" and then try "hard" attempt to terminate the process.
timeout | Wait time in milliseconds between first "soft" and second "hard" attempts to terminate the process. If timeout is zero then use an unsafe process termination: just try to terminate the process without checks that it is really gone. |
Definition at line 628 of file ncbi_process.cpp.
References _ASSERT, CStopWatch::Elapsed(), CProcess::ePid, FALSE, CProcess::GetPid(), CProcess::GetType(), HANDLE, INVALID_HANDLE_VALUE, CProcess::IsAlive(), CProcess::IsCurrent(), kMilliSecondsPerSecond, kWaitPrecisionMs, NULL, CNcbiError::SetFromErrno(), CNcbiError::SetFromWindowsError(), CNcbiError::SetWindowsError(), SleepMilliSec(), CStopWatch::Start(), CProcess::x_CloseHandle(), and CProcess::x_GetHandle().
Referenced by CBLASTSeqToolJob::RequestCancel(), CWindowMaskerJob::RequestCancel(), s_Close(), s_Win_KillGroup(), CBamLoadingJob::x_CreateDataLoader(), and CWNJobWatcher::x_KillNode().
bool CProcess::KillGroup | ( | unsigned long | timeout = kDefaultKillTimeout | ) | const |
Terminate a group of processes.
This method tries to terminate all processes in the group to which process, specified in the constructor, belongs.
timeout | Wait time in milliseconds between first "soft" and second "hard" attempts to terminate the process group. If timeout is zero then use an unsafe process termination: just try to terminate the group without checks that it is really gone. |
Definition at line 919 of file ncbi_process.cpp.
References CProcess::GetPid(), CProcess::KillGroupById(), result, s_Win_KillGroup(), CNcbiError::SetFromErrno(), CStopWatch::Start(), and CProcess::x_GetPid().
Referenced by CRemoteAppReaperTask::operator()(), and s_Close().
|
static |
Terminate a group of processes with specified ID.
Note: Implemented on UNIX only, on Windows returns FALSE.
pgid | Process group ID to terminate. if "pgid" parameter is zero, terminate the process group of the current process |
timeout | Wait time in milliseconds between first "soft" and second "hard" attempts to terminate the process group. If timeout is zero then use an unsafe process termination: just try to terminate the process group without checks whether it is really gone. |
Definition at line 951 of file ncbi_process.cpp.
References _ASSERT, CNcbiError::eNotSupported, kWaitPrecisionMs, CNcbiError::Set(), CNcbiError::SetFromErrno(), and SleepMilliSec().
Referenced by CProcess::KillGroup().
void CInterProcessLock::Lock | ( | const CTimeout & | timeout = CTimeout(CTimeout::eInfinite) , |
const CTimeout & | granularity = CTimeout(CTimeout::eInfinite) |
||
) |
Definition at line 142 of file interprocess_lock.cpp.
References _T_XCSTRING, _VERIFY, close(), CDirEntry::fRead, CDirEntry::fWrite, CTimeout::GetAsMilliSeconds(), HANDLE, CTimeout::IsDefault(), CTimeout::IsInfinite(), kInvalidLockHandle, CInterProcessLock::m_Handle, CInterProcessLock::m_SystemName, CDirEntry::MakeModeT(), min(), NCBI_THROW, NULL, s_Locks, s_UnixLock(), SleepMilliSec(), strerror(), and TRUE.
Referenced by PInterProcessLock::operator()(), and CInterProcessLock::TryLock().
CInterProcessLockException::NCBI_EXCEPTION_DEFAULT | ( | CInterProcessLockException | , |
CCoreException | |||
) |
|
inline |
Definition at line 218 of file interprocess_lock.hpp.
References CInterProcessLock::Lock(), PInterProcessLock::m_Granularity, and PInterProcessLock::m_Timeout.
|
inline |
Definition at line 211 of file interprocess_lock.hpp.
void CPIDGuard::Release | ( | void | ) |
Release PID.
Decrease reference counter for current PID and remove the file if it is not used more (reference counter is 0).
Definition at line 1768 of file ncbi_process.cpp.
References _T_CSTRING, in(), CPIDGuard::m_MTGuard, CPIDGuard::m_Path, CPIDGuard::m_PID, CPIDGuard::m_PIDGuard, NCBI_THROW, NcbiSys_strerror, out(), CGuard< Resource, Lock, Unlock, ReportExceptions >::Release(), CDirEntry::Remove(), and trunc.
Referenced by CPIDGuard::~CPIDGuard().
void CInterProcessLock::Remove | ( | void | ) |
Call Unlock() and removes lock object from the system.
On Unix, the Unlock() method do not remove used lock file from the system, it just release a lock. If you don't need this file anymore, use this method to remove it. We cannot remove it automaticaly in the Unlock(), because on Unix locking/unlocking is not an atomic operations and race condition is possible if at time of deleting some other process wait to acquire a lock using the same lock file.
Definition at line 373 of file interprocess_lock.cpp.
References _T_XCSTRING, kInvalidLockHandle, CInterProcessLock::m_Handle, CInterProcessLock::m_SystemName, NcbiSys_unlink, and CInterProcessLock::Unlock().
void CPIDGuard::Remove | ( | void | ) |
Remove the file.
Remove PID file forcibly, ignoring any reference counter.
Definition at line 1821 of file ncbi_process.cpp.
References CPIDGuard::m_MTGuard, CPIDGuard::m_Path, CPIDGuard::m_PIDGuard, and CDirEntry::Remove().
|
inlineoverridevirtual |
Constructor.
Definition at line 828 of file ncbi_process.hpp.
References CPIDGuardException::m_PID, and out().
bool CInterProcessLock::TryLock | ( | void | ) |
Try to acquire the lock.
Acquire the lock if it can be done right away. Return immediately.
Definition at line 382 of file interprocess_lock.cpp.
References CInterProcessLock::Lock().
void CInterProcessLock::Unlock | ( | void | ) |
Release the lock.
On any error (including when the lock is not held by the process), throw CInterProcessLockException.
Definition at line 320 of file interprocess_lock.cpp.
References _VERIFY, close(), kInvalidLockHandle, CInterProcessLock::m_Handle, CInterProcessLock::m_SystemName, NCBI_THROW, s_Locks, and SEEK_SET.
Referenced by CInterProcessLock::Remove(), and CInterProcessLock::~CInterProcessLock().
void CPIDGuard::UpdatePID | ( | TPid | pid = 0 | ) |
Update PID in the file.
pid | The new process ID to store (defaults to the current PID); useful when the real work occurs in a child process that outlives the parent. |
Definition at line 1842 of file ncbi_process.cpp.
References _T_CSTRING, CProcess::ePid, CCurrentProcess::GetPid(), in(), CPIDGuard::m_MTGuard, CPIDGuard::m_Path, CPIDGuard::m_PID, CPIDGuard::m_PIDGuard, NCBI_THROW, NCBI_THROW2, NcbiSys_strerror, out(), and trunc.
Referenced by CPIDGuard::CPIDGuard().
int CProcess::Wait | ( | unsigned long | timeout = kInfiniteTimeoutMs , |
CExitInfo * | info = 0 |
||
) | const |
Wait until process terminates.
Wait until the process terminates or timeout expires. Return immediately if the specified process has already terminated.
timeout | Time interval in milliseconds (infinite by default) to wait. |
info | Extended exit information for terminated process. Note that if CProcess::Kill() was used to terminate the process then the extended information may not be available. |
Definition at line 1013 of file ncbi_process.cpp.
References _ASSERT, eExitInfo_Alive, eExitInfo_Terminated, eExitInfo_Unknown, CProcess::GetPid(), HANDLE, info, CProcessBase::kInfiniteTimeoutMs, kWaitPrecisionMs, CNcbiError::SetFromErrno(), SleepMilliSec(), CProcess::x_CloseHandle(), and CProcess::x_GetHandle().
Referenced by CRemoteAppReaperTask::operator()(), SGridWorkerNodeImpl::Run(), s_Close(), s_GetBigBedFeats(), s_GetBigBedSummary(), s_GetData(), CExec::Wait(), CProcess::WaitInfinite(), CProcess::WaitTimeout(), CBamLoadingJob::x_CreateDataLoader(), CBLASTSeqToolJob::x_CreateProjectItems(), and CWigGraph::x_RunBigWigScript().
Wait indefinitely until the process terminates.
Definition at line 595 of file ncbi_process.hpp.
References info, CProcessBase::kInfiniteTimeoutMs, and CProcess::Wait().
Wait until the process terminates or timeout expires.
Definition at line 589 of file ncbi_process.hpp.
References info, and CProcess::Wait().
|
inlineoverrideprotectedvirtual |
Definition at line 836 of file ncbi_process.hpp.
References CPIDGuardException::m_PID, and CException::x_Assign().
|
private |
Definition at line 571 of file ncbi_process.cpp.
References CProcess::ePid, and CProcess::GetType().
Referenced by CProcess::GetMemoryUsage(), CProcess::GetTimes(), CProcess::IsAlive(), CProcess::Kill(), and CProcess::Wait().
|
private |
Definition at line 548 of file ncbi_process.cpp.
References CNcbiError::eBadAddress, CProcess::eHandle, FALSE, CProcess::GetHandle(), CProcess::GetPid(), CProcess::GetType(), INVALID_HANDLE_VALUE, NULL, CNcbiError::Set(), CNcbiError::SetFromWindowsError(), and CNcbiError::SetWindowsError().
Referenced by CProcess::GetMemoryUsage(), CProcess::GetTimes(), CProcess::IsAlive(), CProcess::Kill(), and CProcess::Wait().
|
private |
Definition at line 578 of file ncbi_process.cpp.
References CProcess::eHandle, CProcess::GetHandle(), CProcess::GetPid(), and CProcess::GetType().
Referenced by CProcess::GetThreadCount(), and CProcess::KillGroup().
CInterProcessLock::~CInterProcessLock | ( | void | ) |
Call Unlock()
Definition at line 99 of file interprocess_lock.cpp.
References kInvalidLockHandle, CInterProcessLock::m_Handle, and CInterProcessLock::Unlock().
CPIDGuard::~CPIDGuard | ( | void | ) |
Destructor.
Just calls Release();
Definition at line 1760 of file ncbi_process.cpp.
References CPIDGuard::m_MTGuard, CPIDGuard::m_PIDGuard, and CPIDGuard::Release().
size_t CProcessBase::SMemoryUsage::data |
Data segment size.
Definition at line 124 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
|
static |
Default wait time (milliseconds) between "soft" and "hard" attempts to terminate a process.
Definition at line 133 of file ncbi_process.hpp.
Referenced by CPipe::ExecWait(), and s_Close().
const unsigned long kInfiniteTimeoutMs = kMax_ULong |
Infinite timeout in milliseconds.
Definition at line 64 of file ncbi_process.hpp.
Referenced by SGridWorkerNodeImpl::Run(), CExec::Wait(), and CBLASTSeqToolJob::x_CreateProjectItems().
|
static |
Infinite timeout (milliseconds).
Definition at line 136 of file ncbi_process.hpp.
Referenced by CProcess::Wait(), and CProcess::WaitInfinite().
size_t CProcessBase::SMemoryUsage::lib |
Shared library code size.
Definition at line 127 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), and CNetScheduleHandler::x_ProcessHealth().
|
private |
Definition at line 225 of file interprocess_lock.hpp.
Referenced by PInterProcessLock::operator()().
|
private |
Definition at line 189 of file interprocess_lock.hpp.
Referenced by CInterProcessLock::CInterProcessLock(), CInterProcessLock::Lock(), CInterProcessLock::Remove(), CInterProcessLock::Unlock(), and CInterProcessLock::~CInterProcessLock().
|
private |
Status that m_Process represent the current process.
Definition at line 798 of file ncbi_process.hpp.
Referenced by CProcess::IsCurrent().
|
private |
Definition at line 933 of file ncbi_process.hpp.
Referenced by CPIDGuard::CPIDGuard(), CPIDGuard::Release(), CPIDGuard::Remove(), CPIDGuard::UpdatePID(), and CPIDGuard::~CPIDGuard().
|
private |
Original name of the lock.
Definition at line 179 of file interprocess_lock.hpp.
Referenced by CInterProcessLock::CInterProcessLock(), and CInterProcessLock::GetName().
|
private |
Definition at line 931 of file ncbi_process.hpp.
Referenced by CPIDGuard::CPIDGuard(), CPIDGuard::Release(), CPIDGuard::Remove(), and CPIDGuard::UpdatePID().
|
private |
Definition at line 843 of file ncbi_process.hpp.
Referenced by CPIDGuardException::GetPID(), CPIDGuardException::ReportExtra(), and CPIDGuardException::x_Assign().
|
private |
Definition at line 932 of file ncbi_process.hpp.
Referenced by CPIDGuard::Release(), and CPIDGuard::UpdatePID().
|
private |
Definition at line 934 of file ncbi_process.hpp.
Referenced by CPIDGuard::Release(), CPIDGuard::Remove(), CPIDGuard::UpdatePID(), and CPIDGuard::~CPIDGuard().
|
private |
Process identifier.
Definition at line 796 of file ncbi_process.hpp.
Referenced by CProcess::GetHandle(), and CProcess::GetPid().
|
private |
Adjusted name of the lock.
Definition at line 181 of file interprocess_lock.hpp.
Referenced by CInterProcessLock::CInterProcessLock(), CInterProcessLock::GetSystemName(), CInterProcessLock::Lock(), CInterProcessLock::Remove(), and CInterProcessLock::Unlock().
|
private |
Definition at line 224 of file interprocess_lock.hpp.
Referenced by PInterProcessLock::operator()().
|
private |
Type of process identifier.
Definition at line 797 of file ncbi_process.hpp.
Referenced by CProcess::GetType().
size_t CProcessBase::SMemoryUsage::resident |
Resident/working set size (RSS).
RSS is the portion of memory occupied by a process that is held in main memory (RAM).
Definition at line 119 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
size_t CProcessBase::SMemoryUsage::resident_peak |
Peak resident set size ("high water mark")
Definition at line 122 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
size_t CProcessBase::SMemoryUsage::shared |
Shared memory usage.
Definition at line 123 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
size_t CProcessBase::SMemoryUsage::stack |
Stack size of the initial thread in the process.
Definition at line 125 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
|
private |
Process state (unknown/alive/terminated).
Definition at line 553 of file ncbi_process.hpp.
|
private |
Process status information.
Definition at line 554 of file ncbi_process.hpp.
Referenced by CProcess::CExitInfo::CExitInfo().
size_t CProcessBase::SMemoryUsage::swap |
Swap space usage.
Definition at line 128 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), and CNetScheduleHandler::x_ProcessHealth().
size_t CProcessBase::SMemoryUsage::text |
Text (code) segment size.
Definition at line 126 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), and CNetScheduleHandler::x_ProcessHealth().
size_t CProcessBase::SMemoryUsage::total |
Total memory usage.
Definition at line 117 of file ncbi_process.hpp.
Referenced by CCgiApplication::CheckMemoryLimit(), CWNJobWatcher::Notify(), CPubseqGatewayApp::OnInfo(), CAsnSubCacheCreateApplication::Run(), CAlignSort::SortAlignments(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
size_t CProcessBase::SMemoryUsage::total_peak |
Peak total memory usage.
Definition at line 118 of file ncbi_process.hpp.
Referenced by CPubseqGatewayApp::OnInfo(), CNcbiApplicationAPI::x_LogOptions(), and CNetScheduleHandler::x_ProcessHealth().
|
friend |
Definition at line 556 of file ncbi_process.hpp.