A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/ncbi__process_8cpp_source.html below:

NCBI C++ ToolKit: src/corelib/ncbi_process.cpp Source File

41 #if defined(NCBI_OS_UNIX) 47 # include <sys/types.h> 48 # include <sys/time.h> 49 # include <sys/resource.h> 50 # include <sys/times.h> 51 # include <sys/wait.h> 52 # if defined(NCBI_OS_BSD) || defined(NCBI_OS_DARWIN) 53 # include <sys/sysctl.h> 55 # if defined(NCBI_OS_IRIX) 56 # include <sys/sysmp.h> 60 #elif defined(NCBI_OS_MSWIN) 65 # pragma warning (disable : 4191) 70 # include <mach/mach.h> 75 #define NCBI_USE_ERRCODE_X Corelib_Process 105 #define EXIT_INFO_CHECK \ 106  if ( !IsPresent() ) { \ 107  NCBI_THROW(CCoreException, eCore, \ 108  "CProcess::CExitInfo state is unknown. "

\

109

"Please check CExitInfo::IsPresent() first."); \

139 #if defined(NCBI_OS_UNIX) 140  return

WIFEXITED(status) != 0;

141 #elif defined(NCBI_OS_MSWIN) 154 #if defined(NCBI_OS_UNIX) 155  return

WIFSIGNALED(status) != 0;

156 #elif defined(NCBI_OS_MSWIN) 168 #if defined(NCBI_OS_UNIX) 169  return

WEXITSTATUS(status);

170 #elif defined(NCBI_OS_MSWIN) 178  if

( !IsSignaled() ) {

181 #if defined(NCBI_OS_UNIX) 182  return

WTERMSIG(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 TPid

CCurrentProcess::sx_GetPid(EGetPidFlag flag)

201  if

( flag == ePID_GetThread ) {

207  static TPid

s_CurrentPid = 0;

208  static TPid

s_ParentPid = 0;

213

s_CurrentPid = getpid();

214

s_ParentPid = getppid();

222  TPid

thr_pid = CThread::sx_GetThreadPid();

223  if

(thr_pid && thr_pid != pid) {

226

CThread::sx_SetThreadPid(pid);

229

s_ParentPid = getppid();

232  return

flag == ePID_GetCurrent ? s_CurrentPid : s_ParentPid;

239 #if defined(NCBI_OS_MSWIN) 240

return ::GetCurrentProcess();

241 #elif defined(NCBI_OS_UNIX) 249 #if defined(NCBI_OS_MSWIN) 250

return ::GetCurrentProcessId();

251 #elif defined NCBI_THREAD_PID_WORKAROUND 252  return

sx_GetPid(ePID_GetCurrent);

253 #elif defined(NCBI_OS_UNIX) 261 #if defined(NCBI_OS_MSWIN) 262

PROCESSENTRY32 entry;

264  return

entry.th32ParentProcessID;

269 #elif defined NCBI_THREAD_PID_WORKAROUND 270  return

sx_GetPid(ePID_GetParent);

272 #elif defined(NCBI_OS_UNIX) 289

CErrnoKeeper() : m_Errno(errno) {}

290  int

GetErrno()

const

{

return

m_Errno;}

291

~CErrnoKeeper() {errno = m_Errno;}

299

CErrnoKeeper 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"

);

352

CSafeRedirect(

int

fd,

bool

* success_flag) :

353

m_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  void

Redirect(

int

new_fd)

363  if

(new_fd != m_OrigFD) {

364  int error

= ::dup2(new_fd, m_OrigFD);

366

CErrnoKeeper x_errno;

369  "Error redirecting file descriptor #"

<< m_OrigFD <<

373

m_Redirected =

true

;

378

CErrnoKeeper x_errno;

379  if

(m_Redirected && !*m_SuccessFlag) {

381

::dup2(m_DupFD, m_OrigFD);

389  bool

* m_SuccessFlag;

403  class

CBoolResetter {

405

CBoolResetter(

bool

&

val

)

423  "Prohibited, there are already child threads running: "

<<

n

);

426  bool

success_flag =

false

;

428

CSafeRedirect stdin_redirector (

STDIN_FILENO

, &success_flag);

429

CSafeRedirect stdout_redirector(

STDOUT_FILENO

, &success_flag);

430

CSafeRedirect stderr_redirector(STDERR_FILENO, &success_flag);

435  if

((new_fd = ::open(

"/dev/null"

, O_RDONLY)) < 0) {

439

stdin_redirector.Redirect(new_fd);

442  if

((new_fd = ::open(

"/dev/null"

, O_WRONLY)) < 0) {

448

stdout_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

());

464

stderr_redirector.Redirect(new_fd);

481

success_flag =

true

;

490  ERR_POST_X

(2,

"[Daemonize] Failed to immune from " 491  "TTY accruals: "

<< e <<

" ... continuing anyways"

);

495  if

(::chdir(

"/"

) ) {

};

519

CErrnoKeeper x_errno;

522  catch

(exception& e) {

523

CErrnoKeeper x_errno;

528  "CCurrentProcess::Daemonize() not implemented on this platform"

);

550

: m_Process(process),

582

hProcess = ::OpenProcess(desired_access,

FALSE

,

GetPid

());

585

*errcode = ::GetLastError();

598

::CloseHandle(handle);

618  bool

current =

false

;

622 #if defined(NCBI_OS_MSWIN) 635 #if defined(NCBI_OS_UNIX) 636  return

kill(

GetPid

(), 0) == 0 || errno == EPERM;

638 #elif defined(NCBI_OS_MSWIN) 642  return

status == ERROR_ACCESS_DENIED;

645

::GetExitCodeProcess(hProcess, &status);

647  return

status == STILL_ACTIVE;

654 #if defined(NCBI_OS_UNIX) 659  if

(kill(pid, SIGTERM) < 0 && errno == EPERM) {

665  unsigned long

x_timeout = timeout;

667  TPid

reap = 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) {

688

x_timeout -= x_sleep;

693  int

res = kill(pid, SIGKILL);

699

waitpid(pid, 0, WNOHANG);

703  return

kill(pid, 0) < 0;

705 #elif defined(NCBI_OS_MSWIN) 708  bool

safe = (timeout > 0);

720  bool

allow_wait =

true

;

724

hProcess =

x_GetHandle

(PROCESS_CREATE_THREAD | PROCESS_TERMINATE | SYNCHRONIZE);

735  if

(err != ERROR_ACCESS_DENIED) {

750  if

(!::OpenThreadToken(::GetCurrentThread(),

751

TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,

FALSE

, &hToken)) {

752

err = ::GetLastError();

753  if

(err != ERROR_NO_TOKEN) {

758  if

(!::OpenProcessToken(::GetCurrentProcess(),

759

TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) {

767

TOKEN_PRIVILEGES tp, tp_prev;

768  DWORD

tp_prev_size =

sizeof

(tp_prev);

770

tp.PrivilegeCount = 1;

771

tp.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);

781

err = ::GetLastError();

782  if

(err == ERROR_NOT_ALL_ASSIGNED) {

787

::CloseHandle(hToken);

792

hProcess = ::OpenProcess(PROCESS_TERMINATE,

FALSE

,

GetPid

());

795

::AdjustTokenPrivileges(hToken,

FALSE

, &tp_prev,

sizeof

(tp_prev),

NULL

,

NULL

);

796

::CloseHandle(hToken);

805  bool

terminated =

false

;

812  if

( safe && allow_wait ) {

815

FARPROC exitproc = ::GetProcAddress(::GetModuleHandleA(

"KERNEL32.DLL"

),

"ExitProcess"

);

817

hThread = ::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  DWORD

err = ::GetLastError();

829  if

(err == ERROR_INVALID_HANDLE) {

842  if

(safe && terminated) {

848  unsigned long

linger_timeout = (elapsed < timeout) ?

849

(

unsigned long

)((double)timeout - elapsed) : 0;

857  if

(x_sleep > linger_timeout) {

858

x_sleep = linger_timeout;

864

linger_timeout -= x_sleep;

869

::CloseHandle(hThread);

890  HANDLE const

snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

894

PROCESSENTRY32 entry;

895

entry.dwSize =

sizeof

(PROCESSENTRY32);

898  if

(!::Process32First(snapshot, &entry)) {

899

::CloseHandle(snapshot);

903  if

(entry.th32ParentProcessID == pid) {

907

timeout = (elapsed < timeout) ? (

unsigned long

)((double)timeout - elapsed) : 0;

909

::CloseHandle(snapshot);

915

::CloseHandle(snapshot);

920  while

(::Process32Next(snapshot, &entry));

927

timeout = (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  return

errno == ESRCH;

955 #elif defined(NCBI_OS_MSWIN) 962  unsigned long

x_timeout = timeout;

977 #if defined(NCBI_OS_UNIX) 980  if

(kill(-pgid, SIGTERM) < 0 && errno == EPERM) {

986  unsigned long

x_timeout = timeout;

989  TPid

reap = 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) {

1005

x_sleep = x_timeout;

1011

x_timeout -= x_sleep;

1016  int

res = kill(-pgid, SIGKILL);

1022

waitpid(pgid, 0, WNOHANG);

1025  return

kill(-pgid, 0) < 0;

1047 #if defined(NCBI_OS_UNIX) 1054  TPid

ws = waitpid(pid, &status, options);

1060  info

->status = status;

1062  return

WIFEXITED(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  bool

allow_wait =

true

;

1094

allow_wait =

false

;

1104  if

(::GetExitCodeProcess(hProcess, &x_status)) {

1105  if

(x_status == STILL_ACTIVE) {

1106  if

(allow_wait && timeout) {

1108

? INFINITE : (

DWORD

) timeout);

1109  DWORD

ws = ::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) 1162

FILETIME ft_creation, ft_exit, ft_kernel, ft_user;

1166

res = ::GetProcessTimes(handle, &ft_creation, &ft_exit, &ft_kernel, &ft_user);

1169

res = ::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 bool

s_Linux_GetTimes_ProcStat(

TPid

pid,

double

* real,

double

* user,

double

* sys,

CProcess::EWhat

what)

1219

CLinuxFeature::CProcStat ps(pid);

1223  int

fu = 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  return

s_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  int

who = RUSAGE_SELF;

1344

who = RUSAGE_CHILDREN;

1347  #ifdef RUSAGE_THREAD 1348

who = RUSAGE_THREAD;

1358

memset(&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;

1379

clock_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)

1429

dllGetProcessMemoryInfo = 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_) 1548

memset(&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 1597

task_flavor_t flavor = MACH_TASK_BASIC_INFO;

1598  struct

mach_task_basic_info t_info;

1599

mach_msg_type_number_t t_info_count = MACH_TASK_BASIC_INFO_COUNT;

1601

task_flavor_t flavor = TASK_BASIC_INFO;

1602  struct

task_basic_info t_info;

1603

mach_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) 1632

PROCESSENTRY32 entry;

1634  return

entry.cntThreads;

1638 #elif defined(NCBI_OS_LINUX) 1639  return

CLinuxFeature::GetThreadCount(

GetPid

());

1650 #if defined(NCBI_OS_MSWIN) 1651

PROCESSENTRY32 entry;

1653  return

entry.cntThreads;

1657 #elif defined(NCBI_OS_LINUX) 1658  return

CLinuxFeature::GetThreadCount();

1674 #if defined(NCBI_OS_LINUX) 1675  return

CLinuxFeature::GetFileDescriptorsCount(

GetPid

());

1685 #if defined(NCBI_OS_UNIX) 1690

rlim_t cur_limit = -1;

1691

rlim_t max_limit = -1;

1692  if

(getrlimit(RLIMIT_NOFILE, &rlim) == 0) {

1693

cur_limit = rlim.rlim_cur;

1694

max_limit = rlim.rlim_max;

1697

cur_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  int

max_fd = (cur_limit > INT_MAX) ? INT_MAX :

static_cast<int>

(cur_limit);

1712  for

(

int

fd = 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 int

ref = 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  bool

valid_file =

true

;

1879  unsigned int

ref = 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