\
109"Please check CExitInfo::IsPresent() first."); \
139 #if defined(NCBI_OS_UNIX) 140 returnWIFEXITED(status) != 0;
141 #elif defined(NCBI_OS_MSWIN) 154 #if defined(NCBI_OS_UNIX) 155 returnWIFSIGNALED(status) != 0;
156 #elif defined(NCBI_OS_MSWIN) 168 #if defined(NCBI_OS_UNIX) 169 returnWEXITSTATUS(status);
170 #elif defined(NCBI_OS_MSWIN) 178 if( !IsSignaled() ) {
181 #if defined(NCBI_OS_UNIX) 182 returnWTERMSIG(status);
183 #elif defined(NCBI_OS_MSWIN) 195 #ifdef NCBI_THREAD_PID_WORKAROUND 196 # ifndef NCBI_OS_UNIX 197 # error "NCBI_THREAD_PID_WORKAROUND should only be defined on UNIX!" 199 TPidCCurrentProcess::sx_GetPid(EGetPidFlag flag)
201 if( flag == ePID_GetThread ) {
207 static TPids_CurrentPid = 0;
208 static TPids_ParentPid = 0;
213s_CurrentPid = getpid();
214s_ParentPid = getppid();
222 TPidthr_pid = CThread::sx_GetThreadPid();
223 if(thr_pid && thr_pid != pid) {
226CThread::sx_SetThreadPid(pid);
229s_ParentPid = getppid();
232 returnflag == ePID_GetCurrent ? s_CurrentPid : s_ParentPid;
239 #if defined(NCBI_OS_MSWIN) 240return ::GetCurrentProcess();
241 #elif defined(NCBI_OS_UNIX) 249 #if defined(NCBI_OS_MSWIN) 250return ::GetCurrentProcessId();
251 #elif defined NCBI_THREAD_PID_WORKAROUND 252 returnsx_GetPid(ePID_GetCurrent);
253 #elif defined(NCBI_OS_UNIX) 261 #if defined(NCBI_OS_MSWIN) 262PROCESSENTRY32 entry;
264 returnentry.th32ParentProcessID;
269 #elif defined NCBI_THREAD_PID_WORKAROUND 270 returnsx_GetPid(ePID_GetParent);
272 #elif defined(NCBI_OS_UNIX) 289CErrnoKeeper() : m_Errno(errno) {}
290 intGetErrno()
const{
returnm_Errno;}
291~CErrnoKeeper() {errno = m_Errno;}
299CErrnoKeeper x_errno;
315 if(!(
flags& fFF_Exec) && use_async_safe) {
316 ERR_POST_X(3,
Warning<<
"It is not safe to call Fork() from a multithreaded program");
322 if(!(
flags& fFF_Exec)) {
327 if(use_async_safe) {
342 "CCurrentProcess::Fork() not implemented on this platform");
352CSafeRedirect(
intfd,
bool* success_flag) :
353m_OrigFD(fd), m_SuccessFlag(success_flag), m_Redirected(
false)
355 if((m_DupFD = ::fcntl(fd, F_DUPFD, STDERR_FILENO + 1)) < 0) {
357 "Error duplicating file descriptor #"<< fd <<
361 voidRedirect(
intnew_fd)
363 if(new_fd != m_OrigFD) {
364 int error= ::dup2(new_fd, m_OrigFD);
366CErrnoKeeper x_errno;
369 "Error redirecting file descriptor #"<< m_OrigFD <<
373m_Redirected =
true;
378CErrnoKeeper x_errno;
379 if(m_Redirected && !*m_SuccessFlag) {
381::dup2(m_DupFD, m_OrigFD);
389 bool* m_SuccessFlag;
403 classCBoolResetter {
405CBoolResetter(
bool&
val)
423 "Prohibited, there are already child threads running: "<<
n);
426 boolsuccess_flag =
false;
428CSafeRedirect stdin_redirector (
STDIN_FILENO, &success_flag);
429CSafeRedirect stdout_redirector(
STDOUT_FILENO, &success_flag);
430CSafeRedirect stderr_redirector(STDERR_FILENO, &success_flag);
435 if((new_fd = ::open(
"/dev/null", O_RDONLY)) < 0) {
439stdin_redirector.Redirect(new_fd);
442 if((new_fd = ::open(
"/dev/null", O_WRONLY)) < 0) {
448stdout_redirector.Redirect(new_fd);
452 if((new_fd = ::open(
"/dev/null", O_WRONLY | O_APPEND)) < 0) {
457 if((new_fd = ::open(logfile, O_WRONLY | O_APPEND | O_CREAT, 0666)) < 0) {
459 "Unable to open logfile \""<< logfile <<
"\": "<<
s_ErrnoToString());
464stderr_redirector.Redirect(new_fd);
481success_flag =
true;
490 ERR_POST_X(2,
"[Daemonize] Failed to immune from " 491 "TTY accruals: "<< e <<
" ... continuing anyways");
495 if(::chdir(
"/") ) {
};
519CErrnoKeeper x_errno;
522 catch(exception& e) {
523CErrnoKeeper x_errno;
528 "CCurrentProcess::Daemonize() not implemented on this platform");
550: m_Process(process),
582hProcess = ::OpenProcess(desired_access,
FALSE,
GetPid());
585*errcode = ::GetLastError();
598::CloseHandle(handle);
618 boolcurrent =
false;
622 #if defined(NCBI_OS_MSWIN) 635 #if defined(NCBI_OS_UNIX) 636 returnkill(
GetPid(), 0) == 0 || errno == EPERM;
638 #elif defined(NCBI_OS_MSWIN) 642 returnstatus == ERROR_ACCESS_DENIED;
645::GetExitCodeProcess(hProcess, &status);
647 returnstatus == STILL_ACTIVE;
654 #if defined(NCBI_OS_UNIX) 659 if(kill(pid, SIGTERM) < 0 && errno == EPERM) {
665 unsigned longx_timeout = timeout;
667 TPidreap = waitpid(pid, 0, WNOHANG);
669 if(reap != (
TPid)(-1)) {
673 if(errno != ECHILD) {
677 if(kill(pid, 0) < 0)
681 if(x_sleep > x_timeout) {
688x_timeout -= x_sleep;
693 intres = kill(pid, SIGKILL);
699waitpid(pid, 0, WNOHANG);
703 returnkill(pid, 0) < 0;
705 #elif defined(NCBI_OS_MSWIN) 708 boolsafe = (timeout > 0);
720 boolallow_wait =
true;
724hProcess =
x_GetHandle(PROCESS_CREATE_THREAD | PROCESS_TERMINATE | SYNCHRONIZE);
735 if(err != ERROR_ACCESS_DENIED) {
750 if(!::OpenThreadToken(::GetCurrentThread(),
751TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
FALSE, &hToken)) {
752err = ::GetLastError();
753 if(err != ERROR_NO_TOKEN) {
758 if(!::OpenProcessToken(::GetCurrentProcess(),
759TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) {
767TOKEN_PRIVILEGES tp, tp_prev;
768 DWORDtp_prev_size =
sizeof(tp_prev);
770tp.PrivilegeCount = 1;
771tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
772::LookupPrivilegeValue(
NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);
774 if(!::AdjustTokenPrivileges(hToken,
FALSE, &tp,
sizeof(tp), &tp_prev, &tp_prev_size)) {
776::CloseHandle(hToken);
781err = ::GetLastError();
782 if(err == ERROR_NOT_ALL_ASSIGNED) {
787::CloseHandle(hToken);
792hProcess = ::OpenProcess(PROCESS_TERMINATE,
FALSE,
GetPid());
795::AdjustTokenPrivileges(hToken,
FALSE, &tp_prev,
sizeof(tp_prev),
NULL,
NULL);
796::CloseHandle(hToken);
805 boolterminated =
false;
812 if( safe && allow_wait ) {
815FARPROC exitproc = ::GetProcAddress(::GetModuleHandleA(
"KERNEL32.DLL"),
"ExitProcess");
817hThread = ::CreateRemoteThread(hProcess,
NULL, 0, (LPTHREAD_START_ROUTINE)exitproc, 0, 0, 0);
820(::WaitForSingleObject(hProcess, timeout) == WAIT_OBJECT_0)){
827 if( ::TerminateProcess(hProcess, -1) != 0 ) {
828 DWORDerr = ::GetLastError();
829 if(err == ERROR_INVALID_HANDLE) {
842 if(safe && terminated) {
848 unsigned longlinger_timeout = (elapsed < timeout) ?
849(
unsigned long)((double)timeout - elapsed) : 0;
857 if(x_sleep > linger_timeout) {
858x_sleep = linger_timeout;
864linger_timeout -= x_sleep;
869::CloseHandle(hThread);
890 HANDLE constsnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
894PROCESSENTRY32 entry;
895entry.dwSize =
sizeof(PROCESSENTRY32);
898 if(!::Process32First(snapshot, &entry)) {
899::CloseHandle(snapshot);
903 if(entry.th32ParentProcessID == pid) {
907timeout = (elapsed < timeout) ? (
unsigned long)((double)timeout - elapsed) : 0;
909::CloseHandle(snapshot);
915::CloseHandle(snapshot);
920 while(::Process32Next(snapshot, &entry));
927timeout = (elapsed < timeout) ? (
unsigned long)((double)timeout - elapsed) : 0;
929::CloseHandle(snapshot);
936::CloseHandle(snapshot);
945 #if defined(NCBI_OS_UNIX) 948 if(pgid == (
TPid)(-1)) {
951 returnerrno == ESRCH;
955 #elif defined(NCBI_OS_MSWIN) 962 unsigned longx_timeout = timeout;
977 #if defined(NCBI_OS_UNIX) 980 if(kill(-pgid, SIGTERM) < 0 && errno == EPERM) {
986 unsigned longx_timeout = timeout;
989 TPidreap = waitpid(pgid, 0, WNOHANG);
991 if(reap != (
TPid)(-1)) {
995 if(errno != ECHILD) {
999 if(kill(-pgid, 0) < 0) {
1004 if(x_sleep > x_timeout) {
1005x_sleep = x_timeout;
1011x_timeout -= x_sleep;
1016 intres = kill(-pgid, SIGKILL);
1022waitpid(pgid, 0, WNOHANG);
1025 returnkill(-pgid, 0) < 0;
1047 #if defined(NCBI_OS_UNIX) 1054 TPidws = waitpid(pid, &status, options);
1060 info->status = status;
1062 returnWIFEXITED(status) ? WEXITSTATUS(status) : -1;
1063}
else if(ws == 0) {
1073 if(x_sleep > timeout) {
1078}
else if(errno != EINTR) {
1086 #elif defined(NCBI_OS_MSWIN) 1088 boolallow_wait =
true;
1094allow_wait =
false;
1104 if(::GetExitCodeProcess(hProcess, &x_status)) {
1105 if(x_status == STILL_ACTIVE) {
1106 if(allow_wait && timeout) {
1108? INFINITE : (
DWORD) timeout);
1109 DWORDws = ::WaitForSingleObject(hProcess, tv);
1113 _ASSERT(x_status == STILL_ACTIVE);
1116 if(::GetExitCodeProcess(hProcess, &x_status)) {
1117 if(x_status != STILL_ACTIVE) {
1140 if(
info&& x_status == STILL_ACTIVE) {
1146 info->status = x_status;
1158 #if defined(NCBI_OS_MSWIN) 1162FILETIME ft_creation, ft_exit, ft_kernel, ft_user;
1166res = ::GetProcessTimes(handle, &ft_creation, &ft_exit, &ft_kernel, &ft_user);
1169res = ::GetThreadTimes(handle, &ft_creation, &ft_exit, &ft_kernel, &ft_user);
1181::GetSystemTimeAsFileTime(&ft_sys);
1185 i.LowPart = ft_creation.dwLowDateTime;
1186 i.HighPart = ft_creation.dwHighDateTime;
1188 i.LowPart = ft_sys.dwLowDateTime;
1189 i.HighPart = ft_sys.dwHighDateTime;
1192 i.QuadPart = v_diff;
1193*real = (
i.LowPart + ((
Uint8)
i.HighPart << 32)) * 1.0e-7;
1196*sys = (ft_kernel.dwLowDateTime + ((
Uint8) ft_kernel.dwHighDateTime << 32)) * 1e-7;
1199*user = (ft_user.dwLowDateTime + ((
Uint8) ft_user.dwHighDateTime << 32)) * 1e-7;
1206 #if defined(NCBI_OS_LINUX) 1207 bools_Linux_GetTimes_ProcStat(
TPidpid,
double* real,
double* user,
double* sys,
CProcess::EWhatwhat)
1219CLinuxFeature::CProcStat ps(pid);
1223 intfu = 14, fs = 15;
1233 if(start > 0 && uptime > 0) {
1234*real = uptime - (double)start / (
double)tick;
1268 #if defined(NCBI_OS_MSWIN) 1285 #elif defined(NCBI_OS_UNIX) 1287 # if defined(NCBI_OS_LINUX) 1288 returns_Linux_GetTimes_ProcStat(
GetPid(), real, user, sys, what);
1307 #if defined(NCBI_OS_MSWIN) 1323 #elif defined(NCBI_OS_UNIX) 1328 # if defined(NCBI_OS_LINUX) 1332 if( s_Linux_GetTimes_ProcStat(0
, real, user, sys, what) ) {
1337 # if defined(HAVE_GETRUSAGE) 1338 intwho = RUSAGE_SELF;
1344who = RUSAGE_CHILDREN;
1347 #ifdef RUSAGE_THREAD 1348who = RUSAGE_THREAD;
1358memset(&ru,
'\0',
sizeof(ru));
1359 if(getrusage(who, &ru) != 0) {
1364*user = double(ru.ru_utime.tv_sec) + double(ru.ru_utime.tv_usec) / 1e6;
1367*sys = double(ru.ru_stime.tv_sec) + double(ru.ru_stime.tv_usec) / 1e6;
1379clock_t
t= times(&
buf);
1380 if(
t== (clock_t)(-1) ) {
1390*user = (double)
buf.tms_utime / (
double)tick;
1393*sys = (double)
buf.tms_stime / (
double)tick;
1405 #if defined(NCBI_OS_MSWIN) 1427 BOOL(STDMETHODCALLTYPE
FAR* dllGetProcessMemoryInfo)
1429dllGetProcessMemoryInfo = psapi_dll.
GetEntryPoint_Func(
"GetProcessMemoryInfo", &dllGetProcessMemoryInfo);
1430 if(dllGetProcessMemoryInfo) {
1431 if( !dllGetProcessMemoryInfo(handle, memcounters,
sizeof(memcounters)) ) {
1478 #if defined(NCBI_OS_MSWIN) 1488 #elif defined(NCBI_OS_LINUX) 1502 #if defined(NCBI_OS_MSWIN) 1505 #elif defined(NCBI_OS_LINUX) 1510 #elif defined(NCBI_OS_SOLARIS) 1519 #elif defined(HAVE_GETRUSAGE) 1538 #if defined(NCBI_OS_LINUX_) 1548memset(&ru,
'\0',
sizeof(ru));
1549 if(getrusage(RUSAGE_SELF, &ru) == 0) {
1551 #if defined(NCBI_OS_DARWIN) 1553 usage.total_peak = ru.ru_maxrss;
1554 usage.resident_peak = ru.ru_maxrss;
1557 usage.resident_peak = ru.ru_maxrss * 1024;
1558 usage.total_peak = ru.ru_maxrss * 1024;
1560 #if !defined(NCBI_OS_DARWIN) 1568 #define KBT(v) ((v) * 1024 / ticks) 1569 usage.total = KBT(ru.ru_ixrss + ru.ru_idrss + ru.ru_isrss);
1570 if(
usage.total > 0) {
1572 usage.total_peak = KBT(ru.ru_ixrss + ru.ru_isrss) + maxrss;
1573 usage.resident = KBT(ru.ru_idrss);
1574 usage.resident_peak = maxrss;
1575 usage.shared = KBT(ru.ru_ixrss);
1576 usage.data = KBT(ru.ru_idrss);
1577 usage.stack = KBT(ru.ru_isrss);
1580 usage.total_peak = maxrss;
1581 usage.resident_peak = maxrss;
1584 #if defined(NCBI_OS_DARWIN) 1585 if(
usage.total > 0) {
1594 #if defined(NCBI_OS_DARWIN) 1596 #ifdef MACH_TASK_BASIC_INFO 1597task_flavor_t flavor = MACH_TASK_BASIC_INFO;
1598 structmach_task_basic_info t_info;
1599mach_msg_type_number_t t_info_count = MACH_TASK_BASIC_INFO_COUNT;
1601task_flavor_t flavor = TASK_BASIC_INFO;
1602 structtask_basic_info t_info;
1603mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
1605 if(task_info(mach_task_self(), flavor, (task_info_t)&t_info, &t_info_count) == KERN_SUCCESS) {
1606 usage.total = t_info.resident_size;
1607 usage.resident = t_info.resident_size;
1611 if(
usage.resident_peak <
usage.resident) {
1631 #if defined(NCBI_OS_MSWIN) 1632PROCESSENTRY32 entry;
1634 returnentry.cntThreads;
1638 #elif defined(NCBI_OS_LINUX) 1639 returnCLinuxFeature::GetThreadCount(
GetPid());
1650 #if defined(NCBI_OS_MSWIN) 1651PROCESSENTRY32 entry;
1653 returnentry.cntThreads;
1657 #elif defined(NCBI_OS_LINUX) 1658 returnCLinuxFeature::GetThreadCount();
1674 #if defined(NCBI_OS_LINUX) 1675 returnCLinuxFeature::GetFileDescriptorsCount(
GetPid());
1685 #if defined(NCBI_OS_UNIX) 1690rlim_t cur_limit = -1;
1691rlim_t max_limit = -1;
1692 if(getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
1693cur_limit = rlim.rlim_cur;
1694max_limit = rlim.rlim_max;
1697cur_limit =
static_cast<rlim_t
>(sysconf(_SC_OPEN_MAX));
1700*soft_limit = (cur_limit > INT_MAX) ? INT_MAX :
static_cast<int>(cur_limit);
1703*hard_limit = (max_limit > INT_MAX) ? INT_MAX :
static_cast<int>(max_limit);
1706 #if defined(NCBI_OS_LINUX) 1707 n= CLinuxFeature::GetFileDescriptorsCount(
GetPid());
1710 if(n < 0 && cur_limit > 0) {
1711 intmax_fd = (cur_limit > INT_MAX) ? INT_MAX :
static_cast<int>(cur_limit);
1712 for(
intfd = 0; fd < max_fd; ++fd) {
1713 if(fcntl(fd, F_GETFD, 0) == -1) {
1714 if(errno == EBADF) {
1727 if( soft_limit ) { *soft_limit = -1; }
1728 if( hard_limit ) { *hard_limit = -1; }
1767 if(real_dir.empty()) {
1802 unsigned intref = 0;
1808 if(
m_PID!= pid ) {
1819 if(
out.good() ) {
1820 out<< pid << endl << ref << endl;
1822 if( !
out.good() ) {
1824 "Unable to write into PID file "+
m_Path+
": " 1878 boolvalid_file =
true;
1879 unsigned intref = 1;
1895 in>> old_pid >> ref;
1896 if( old_pid == pid ) {
1902 "Process is still running", old_pid);
1912 if(
out.good() ) {
1913 out<< pid << endl << ref << endl;
1915 if( !
out.good() ) {
1917 "Unable to write into PID file "+
m_Path+
": " 1927 switch(GetErrCode()) {
1929 case eWrite:
return "eWrite";
void Release()
Manually force the resource to be released.
Extended exit information for waited process.
static clock_t GetClockTicksPerSecond(void)
Get number of (statistics) clock ticks per second.
static double GetUptime(void)
Get system uptime in seconds.
static bool FindProcessEntry(DWORD id, PROCESSENTRY32 &entry)
Find process entry information by process identifier (pid).
std::ofstream out("events_result.xml")
main entry point for tests
@ eTriState_False
The value is equivalent to false/no.
@ eTriState_True
The value is equivalent to true/yes.
@ eTriState_Unknown
The value is indeterminate.
CDiagContext & GetDiagContext(void)
Get diag context instance.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
static void UpdateOnFork(TOnForkFlags flags)
Update diagnostics after fork().
void PrintStop(void)
Print exit message.
@ fOnFork_ResetTimer
Reset execution timer.
@ fOnFork_AsyncSafe
After a fork() in a multithreaded program, the child can safely call only async-signal-safe functions...
@ fOnFork_PrintStart
Log app-start.
TFunc GetEntryPoint_Func(const string &name, TFunc *func)
Get DLLs entry point (function).
static void SetFromWindowsError(void)
Set last error on MS Windows using GetLastError()
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
static void SetFromErrno(void)
Set last error using current "errno" code.
void Warning(CExceptionArgs_Base &args)
static void Set(ECode code)
Set last error using native error code enum.
#define NCBI_THROW2(exception_class, err_code, message, extra)
Throw exception with extra parameter.
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
static void SetWindowsError(int native_err_code)
Set last error using Windows-specific error code.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
@ eUnknown
Unknown error.
static string GetTmpDir(void)
Get temporary directory.
Int8 GetLength(void) const
Get size of file.
virtual bool Remove(TRemoveFlags flags=eRecursive) const
Remove a directory entry.
static string MakePath(const string &dir=kEmptyStr, const string &base=kEmptyStr, const string &ext=kEmptyStr)
Assemble a path from basic components.
static void SplitPath(const string &path, string *dir=0, string *base=0, string *ext=0)
Split a path string into its basic components.
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
virtual const char * GetErrCodeString(void) const override
bool GetTimes(double *real, double *user, double *sys, EWhat what=eProcess)
Get process execution times.
static int GetThreadCount(void)
Get the number of threads in the current process.
TPid x_GetPid(void) const
~CPIDGuard(void)
Destructor.
CPIDGuard(const string &filename)
Create/check PID file.
TProcessHandle x_GetHandle(DWORD desired_access, DWORD *errcode=0) const
static TPid GetParentPid(void)
Get process identifier (pid) for the parent of the current process.
bool IsPresent(void) const
TRUE if the object contains information about the process state.
EType
How to interpret the used process identifier.
TProcessHandle GetHandle(void) const
Get stored process handle.
static bool KillGroupById(TPid pgid, unsigned long timeout=kDefaultKillTimeout)
Terminate a group of processes with specified ID.
bool KillGroup(unsigned long timeout=kDefaultKillTimeout) const
Terminate a group of processes.
static TPid GetPid(void)
Get process identifier (pid) for the current process.
int status
Process status information.
unsigned int TDaemonFlags
Bit-wise OR of FDaemonFlags.
static int 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 des...
EType m_Type
Type of process identifier.
EWhat
Process information "target".
unique_ptr< CInterProcessLock > m_MTGuard
bool IsExited(void) const
TRUE if the process terminated normally.
bool GetMemoryUsage(SMemoryUsage &usage)
Get process memory usage.
int GetSignal(void) const
Get the signal number that has caused the process to terminate (UNIX only).
bool Kill(unsigned long timeout=kDefaultKillTimeout)
Terminate process.
static bool GetMemoryUsage(SMemoryUsage &usage)
Get current process memory usage.
ETriState m_IsCurrent
Status that m_Process represent the current process.
static TPid Daemonize(const char *logfile=0, TDaemonFlags flags=0)
Go daemon.
static TPid Fork(TForkFlags flags=fFF_UpdateDiag)
Fork the process.
unique_ptr< CInterProcessLock > m_PIDGuard
static const unsigned long kInfiniteTimeoutMs
Infinite timeout (milliseconds).
CExitInfo(void)
Constructor.
intptr_t m_Process
Process identifier.
bool IsCurrent(void)
Checks that stored process identifier (pid) represent the current process.
int Wait(unsigned long timeout=kInfiniteTimeoutMs, CExitInfo *info=0) const
Wait until process terminates.
void x_CloseHandle(TProcessHandle handle) const
int GetThreadCount(void)
Get the number of threads in the process.
static const unsigned long kDefaultKillTimeout
Default wait time (milliseconds) between "soft" and "hard" attempts to terminate a process.
unsigned TForkFlags
Bit-wise OR of FForkFlags.
pid_t TPid
Process identifier (PID) and process handle.
bool IsAlive(void) const
TRUE if the process is still alive.
void Release(void)
Release PID.
bool IsSignaled(void) const
TRUE if the process terminated by a signal (UNIX only).
CProcess(void)
Default constructor. Uses the current process pid.
TPid GetPid(void) const
Get stored process identifier (pid).
static bool GetTimes(double *real, double *user, double *sys, EWhat what=eProcess)
Get current process execution times.
bool IsAlive(void) const
Check for process existence.
static TProcessHandle GetHandle(void)
Get process handle for the current process (esp.
int GetFileDescriptorsCount(void)
Get the number of file descriptors consumed by the current process.
EType GetType(void) const
Get type of stored process identifier.
void UpdatePID(TPid pid=0)
Update PID in the file.
void Remove(void)
Remove the file.
int GetExitCode(void) const
Get process exit code.
@ ePid
A real process identifier (pid).
@ eHandle
A process handle (MS Windows).
@ eWrite
Unable to write into the PID file.
@ eStillRunning
The process listed in the file is still around.
@ eChildren
All children of the calling process.
@ eThread
Current thread.
@ eProcess
Current process.
@ fFF_UpdateDiag
Reset diagnostics timer and log an app-start message in the child process.
@ fFF_AllowExceptions
Throw an exception on error.
@ fDF_KeepCWD
Don't change CWD to "/".
@ fDF_KeepParent
Do not exit the parent process but return.
@ fDF_KeepStdout
Keep stdout open as "/dev/null" (WO)
@ fDF_AllowExceptions
Throw an exception in case of an error.
@ fDF_KeepStdin
Keep stdin open as "/dev/null" (RO)
@ fDF_AllowThreads
Do not fail if pre-existing threads are detected.
@ fDF_ImmuneTTY
Make daemon immune to re-acquiring a controlling terminal.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
@ fConvErr_NoThrow
Do not throw an exception on error.
static unsigned int GetThreadsCount()
Get total amount of threads This amount does not contain main thread.
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
const long kMilliSecondsPerSecond
Number milliseconds in one second.
void Start(void)
Start the timer.
#define INVALID_HANDLE_VALUE
A value for an invalid file handle.
#define HANDLE
An abstraction for a file handle.
Definition of all error codes used in corelib (xncbi.lib).
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines MS Windows specific private functions and classes.
Private UNIX specific features.
bool s_Win_GetMemoryUsage(HANDLE handle, CProcess::SMemoryUsage &usage)
TPid s_Daemonize(const char *logfile, CCurrentProcess::TDaemonFlags flags)
bool s_Win_GetHandleTimes(HANDLE handle, double *real, double *user, double *sys, CProcess::EWhat what)
static bool s_Win_KillGroup(DWORD pid, CStopWatch *timer, unsigned long &timeout)
bool s_Win_GetMemoryCounters(HANDLE handle, SProcessMemoryCounters &memcounters)
const unsigned long kWaitPrecisionMs
DEFINE_STATIC_FAST_MUTEX(s_CorelibDaemonizeMutex)
static string s_ErrnoToString()
Defines process management classes.
Static variables safety - create on demand, destroy on application termination.
#define FALSE
bool replacment for C indicating false.
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
bool GetMemoryUsage(size_t *total, size_t *resident, size_t *shared)
Defines NCBI C++ diagnostic APIs, classes, and macros.
Define class Dll and for Portable DLL handling.
Defines NCBI C++ Toolkit portable error codes.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Multi-threading â classes, functions, and features.
Defines: CTimeFormat - storage class for time format.
std::istream & in(std::istream &in_, double &x_)
static const TModelUnit kUndefined
Process memory usage information, in bytes.
SIZE_T QuotaPagedPoolUsage
SIZE_T QuotaNonPagedPoolUsage
SIZE_T QuotaPeakNonPagedPoolUsage
SIZE_T PeakWorkingSetSize
SIZE_T QuotaPeakPagedPoolUsage
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4