NCBI C++ ToolKit
ncbi_system.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbi_system.cpp 76213 2017-01-24 15:14:24Z vasilche $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Vladimir Ivanov, Denis Vakatov, Anton Lavrentiev
27  *
28  * File Description: System functions
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/ncbimtx.hpp>
34 #include <corelib/ncbi_system.hpp>
36 #include <corelib/error_codes.hpp>
37 #include <corelib/ncbierror.hpp>
38 #include "ncbisys.hpp"
39 
40 
41 #define NCBI_USE_ERRCODE_X Corelib_System
42 
43 #if defined(NCBI_OS_UNIX)
44 # include <sys/mman.h>
45 # if defined(NCBI_OS_SOLARIS)
46 # include <corelib/ncbifile.hpp>
47 # ifndef VALID_ATTR // correlated with madvise() prototype
48 extern "C" {
49  extern int madvise(caddr_t, size_t, int);
50 }
51 # endif
52 # endif //NCBI_OS_SOLARIS
53 # include <sys/time.h>
54 # include <sys/resource.h>
55 # include <sys/times.h>
56 # include <sys/types.h>
57 # include <dirent.h>
58 # include <limits.h>
59 # include <time.h>
60 # include <unistd.h>
61 # include <fcntl.h>
62 # if defined(NCBI_OS_BSD) || defined(NCBI_OS_DARWIN)
63 # include <sys/sysctl.h>
64 # endif //NCBI_OS_BSD || NCBI_OS_DARWIN
65 # if defined(NCBI_OS_IRIX)
66 # include <sys/sysmp.h>
67 # endif //NCBI_OS_IRIX
68 # include "ncbi_os_unix_p.hpp"
69 # define USE_SETMEMLIMIT
70 # define USE_SETCPULIMIT
71 # define HAVE_MADVISE 1
72 #endif //NCBI_OS_UNIX
73 
74 #ifdef NCBI_OS_DARWIN
75 extern "C" {
76 # include <mach/mach.h>
77 # include <mach/mach_host.h>
78 # include <mach/host_info.h>
79 } /* extern "C" */
80 #endif //NCBI_OS_DARWIN
81 
82 #ifdef USE_SETCPULIMIT
83 # include <signal.h>
84 #endif //USE_SETCPULIMIT
85 
86 #ifdef NCBI_OS_MSWIN
87 # include <corelib/ncbidll.hpp>
88 # include <crtdbg.h>
89 # include <stdlib.h>
90 # include <windows.h>
91 # include "ncbi_os_mswin_p.hpp"
92 
94 {
105 };
106 
107 #endif //NCBI_OS_MSWIN
108 
109 
111 
112 
113 // MIPSpro 7.3 workarounds:
114 // 1) it declares set_new_handler() in both global and std:: namespaces;
115 // 2) it apparently gets totally confused by `extern "C"' inside a namespace.
116 #if defined(NCBI_COMPILER_MIPSPRO)
117 # define set_new_handler std::set_new_handler
118 #else
119 extern "C" {
120  static void s_ExitHandler(void);
121  static void s_SignalHandler(int sig);
122 }
123 #endif //NCBI_COMPILER_MIPSPRO
124 
125 
126 #ifdef NCBI_OS_UNIX
127 
128 DEFINE_STATIC_FAST_MUTEX(s_ExitHandler_Mutex);
129 static bool s_ExitHandlerIsSet = false;
132 static size_t s_MemoryLimitSoft = 0;
133 static size_t s_MemoryLimitHard = 0;
134 static size_t s_CpuTimeLimit = 0;
135 static char* s_ReserveMemory = 0;
138 
139 
140 #if !defined(CLK_TCK) && defined(CLOCKS_PER_SEC)
141 # define CLK_TCK CLOCKS_PER_SEC
142 #endif
143 
144 
145 // Routine to be called at the exit from application
146 // It is not async-safe, so using it with SetCpuLimits() can lead to coredump
147 // and program crash. Be aware.
148 //
149 static void s_ExitHandler(void)
150 {
151  CFastMutexGuard LOCK(s_ExitHandler_Mutex);
152 
153  // Free reserved memory
154  if ( s_ReserveMemory ) {
155  delete[] s_ReserveMemory;
156  s_ReserveMemory = 0;
157  }
158 
159  // User defined dump
160  if ( s_PrintHandler ) {
161  size_t limit_size;
162 
163  switch ( s_ExitCode ) {
164  case eLEC_Memory: {
165  limit_size = s_MemoryLimitSoft;
166  break;
167  }
168  case eLEC_Cpu: {
169  limit_size = s_CpuTimeLimit;
170  break;
171  }
172  default:
173  return;
174  }
175  // Call user's print handler
176  (*s_PrintHandler)(s_ExitCode, limit_size, s_TimeSet.Get(),
178  return;
179  }
180 
181  // Standard dump
182  switch ( s_ExitCode ) {
183 
184  case eLEC_Memory:
185  {
186  ERR_POST_X(1, "Memory heap limit exceeded in allocating memory " \
187  "by operator new (" << s_MemoryLimitSoft << " bytes)");
188  break;
189  }
190 
191  case eLEC_Cpu:
192  {
193  ERR_POST_X(2, "CPU time limit exceeded (" << s_CpuTimeLimit << " sec)");
194  tms buffer;
195  if (times(&buffer) == (clock_t)(-1)) {
196  ERR_POST_X(3, "Error in getting CPU time consumed by program");
197  break;
198  }
199  clock_t tick = sysconf(_SC_CLK_TCK);
200 #if defined(CLK_TCK)
201  if (!tick || tick == (clock_t)(-1))
202  tick = CLK_TCK;
203 #elif defined(CLOCKS_PER_SEC)
204  if (!tick || tick == (clock_t)(-1))
205  tick = CLOCKS_PER_SEC;
206 #endif
207  if (tick == (clock_t)(-1))
208  tick = 0;
209  ERR_POST_X(4, Note << "\tuser CPU time : " <<
210  buffer.tms_utime/(tick ? tick : 1) <<
211  (tick ? " sec" : " tick"));
212  ERR_POST_X(5, Note << "\tsystem CPU time : " <<
213  buffer.tms_stime/(tick ? tick : 1) <<
214  (tick ? " sec" : " tick"));
215  ERR_POST_X(6, Note << "\ttotal CPU time : " <<
216  (buffer.tms_stime + buffer.tms_utime)/(tick ? tick : 1) <<
217  (tick ? " sec" : " tick"));
218  break;
219  }
220 
221  default:
222  return;
223  }
224 
225  // Write program's time
227  CTime et(2000, 1, 1);
228  et.AddSecond((int) (ct.GetTimeT() - s_TimeSet->GetTimeT()));
229  ERR_POST_X(7, Note << "Program's time: " << Endm <<
230  "\tstart limit - " << s_TimeSet->AsString() << Endm <<
231  "\ttermination - " << ct.AsString() << Endm);
232  et.SetFormat("h:m:s");
233  ERR_POST_X(8, Note << "\texecution - " << et.AsString());
234 }
235 
236 
237 // Set routine to be called at the exit from application
238 //
240  TLimitsPrintParameter parameter)
241 
242 {
243  // Set exit routine if it not set yet
244  CFastMutexGuard LOCK(s_ExitHandler_Mutex);
245  if ( !s_ExitHandlerIsSet ) {
246  if (atexit(s_ExitHandler) != 0) {
247  return false;
248  }
249  s_ExitHandlerIsSet = true;
250  s_TimeSet->SetCurrent();
251 
252  // Store new print handler and its parameter
253  s_PrintHandler = handler;
254  s_PrintHandlerParam = parameter;
255 
256  // Reserve some memory (10Kb) to allow the diagnostic API
257  // print messages on exit if memory limit is set.
258  s_ReserveMemory = new char[10*1024];
259  }
260  return true;
261 }
262 
263 #endif //NCBI_OS_UNIX
264 
265 
266 
267 /////////////////////////////////////////////////////////////////////////////
268 //
269 // SetHeapLimit
270 //
271 
272 #ifdef USE_SETMEMLIMIT
273 
274 // Handler for operator new
275 static void s_NewHandler(void)
276 {
277  s_ExitCode = eLEC_Memory;
278  exit(-1);
279 }
280 
281 
282 bool SetMemoryLimit(size_t max_size,
284  TLimitsPrintParameter parameter)
285 {
286  if (s_MemoryLimitSoft == max_size) {
287  return true;
288  }
289  if (!s_SetExitHandler(handler, parameter)) {
290  return false;
291  }
292  CFastMutexGuard LOCK(s_ExitHandler_Mutex);
293 
294  rlimit rl;
295  if ( max_size ) {
296  set_new_handler(s_NewHandler);
297  rl.rlim_cur = rl.rlim_max = max_size;
298  } else {
299  set_new_handler(0);
300  rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
301  }
302  if (setrlimit(RLIMIT_DATA, &rl) != 0) {
303  return false;
304  }
305 # if !defined(NCBI_OS_SOLARIS)
306  if (setrlimit(RLIMIT_AS, &rl) != 0) {
307  return false;
308  }
309 # endif //NCBI_OS_SOLARIS
310 
311  s_MemoryLimitSoft = max_size;
312  s_MemoryLimitHard = max_size;
313  if ( max_size ) {
314  set_new_handler(s_NewHandler);
315  } else {
316  set_new_handler(0);
317  }
318  return true;
319 }
320 
321 
322 bool SetMemoryLimitSoft(size_t max_size,
324  TLimitsPrintParameter parameter)
325 {
326  if (s_MemoryLimitSoft == max_size) {
327  return true;
328  }
329  if (!s_SetExitHandler(handler, parameter)) {
330  return false;
331  }
332  CFastMutexGuard LOCK(s_ExitHandler_Mutex);
333 
334  rlimit rl;
335  if (getrlimit(RLIMIT_DATA, &rl) != 0) {
336  return false;
337  }
338  if ( max_size ) {
339  rl.rlim_cur = max_size;
340  } else {
341  rl.rlim_cur = RLIM_INFINITY;
342  }
343  if (setrlimit(RLIMIT_DATA, &rl) != 0) {
344  return false;
345  }
346 # if !defined(NCBI_OS_SOLARIS)
347  rlimit rlas;
348  if (getrlimit(RLIMIT_AS, &rlas) != 0) {
349  return false;
350  }
351  rl.rlim_max = rlas.rlim_max;
352  if (setrlimit(RLIMIT_AS, &rl) != 0) {
353  return false;
354  }
355 # endif //NCBI_OS_SOLARIS
356 
357  s_MemoryLimitSoft = max_size;
358  if ( max_size ) {
359  set_new_handler(s_NewHandler);
360  } else {
361  set_new_handler(0);
362  }
363  return true;
364 }
365 
366 
367 bool SetMemoryLimitHard(size_t max_size,
369  TLimitsPrintParameter parameter)
370 {
371  if (s_MemoryLimitHard == max_size) {
372  return true;
373  }
374  if (!s_SetExitHandler(handler, parameter)) {
375  return false;
376  }
377  CFastMutexGuard LOCK(s_ExitHandler_Mutex);
378 
379  size_t cur_soft_limit = 0;
380  rlimit rl;
381  if (getrlimit(RLIMIT_DATA, &rl) != 0) {
382  return false;
383  }
384  if ( max_size ) {
385  rl.rlim_max = max_size;
386  if (rl.rlim_cur > max_size) {
387  rl.rlim_cur = max_size;
388  }
389  cur_soft_limit = rl.rlim_cur;
390  } else {
391  rl.rlim_max = RLIM_INFINITY;
392  }
393  if (setrlimit(RLIMIT_DATA, &rl) != 0) {
394  return false;
395  }
396 # if !defined(NCBI_OS_SOLARIS)
397  rlimit rlas;
398  if (getrlimit(RLIMIT_AS, &rlas) != 0) {
399  return false;
400  }
401  if ( max_size ) {
402  rlas.rlim_max = max_size;
403  // Descrease current soft limit of the virtual memory
404  // to the size of data segment -- min(DATA,AS).
405  if (rlas.rlim_cur > cur_soft_limit) {
406  rlas.rlim_cur = cur_soft_limit;
407  }
408  // And use this size as current value for the soft limit
409  // in the print handler
410  cur_soft_limit = rlas.rlim_cur;
411  } else {
412  rlas.rlim_max = RLIM_INFINITY;
413  }
414  if (setrlimit(RLIMIT_AS, &rlas) != 0) {
415  return false;
416  }
417 # endif //NCBI_OS_SOLARIS
418 
419  s_MemoryLimitSoft = cur_soft_limit;
420  s_MemoryLimitHard = max_size;
421  if ( max_size ) {
422  set_new_handler(s_NewHandler);
423  } else {
424  set_new_handler(0);
425  }
426  return true;
427 }
428 
429 
430 // @deprecated
431 bool SetHeapLimit(size_t max_size,
433  TLimitsPrintParameter parameter)
434 {
435  if (s_MemoryLimitSoft == max_size) {
436  return true;
437  }
438  if (!s_SetExitHandler(handler, parameter)) {
439  return false;
440  }
441  CFastMutexGuard LOCK(s_ExitHandler_Mutex);
442 
443  rlimit rl;
444  if ( max_size ) {
445  rl.rlim_cur = rl.rlim_max = max_size;
446  } else {
447  rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
448  }
449  if (setrlimit(RLIMIT_DATA, &rl) != 0) {
450  return false;
451  }
452  s_MemoryLimitSoft = max_size;
453  if ( max_size ) {
454  set_new_handler(s_NewHandler);
455  } else {
456  set_new_handler(0);
457  }
458  return true;
459 }
460 
461 
462 #else
463 
464 bool SetMemoryLimit(size_t max_size,
466  TLimitsPrintParameter parameter)
467 {
468  return false;
469 }
470 
471 bool SetMemoryLimitSoft(size_t max_size,
473  TLimitsPrintParameter parameter)
474 {
475  return false;
476 }
477 
478 bool SetMemoryLimitHard(size_t max_size,
480  TLimitsPrintParameter parameter)
481 {
482  return false;
483 }
484 
485 bool SetHeapLimit(size_t max_size,
487  TLimitsPrintParameter parameter)
488 {
489  return false;
490 }
491 
492 #endif //USE_SETMEMLIMIT
493 
494 
495 
496 /////////////////////////////////////////////////////////////////////////////
497 //
498 // SetCpuTimeLimit
499 //
500 
501 #ifdef USE_SETCPULIMIT
502 
503 static void s_SignalHandler(int _DEBUG_ARG(sig))
504 {
505  _ASSERT(sig == SIGXCPU);
506  _VERIFY(signal(SIGXCPU, SIG_IGN) != SIG_ERR);
507  s_ExitCode = eLEC_Cpu;
508  // _exit() does not go over atexit() chain, so just call registered
509  // handler directly. Be aware that it should be async-safe!
510  if (s_ExitHandlerIsSet) {
511  s_ExitHandler();
512  }
513  _exit(-1);
514 }
515 
516 bool SetCpuTimeLimit(unsigned int max_cpu_time,
517  unsigned int terminate_delay_time,
519  TLimitsPrintParameter parameter)
520 {
521  if (s_CpuTimeLimit == max_cpu_time) {
522  return true;
523  }
524  if (!s_SetExitHandler(handler, parameter)) {
525  return false;
526  }
527  CFastMutexGuard LOCK(s_ExitHandler_Mutex);
528 
529  rlimit rl;
530  if ( max_cpu_time ) {
531  rl.rlim_cur = max_cpu_time;
532  rl.rlim_max = max_cpu_time + terminate_delay_time;
533  } else {
534  rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
535  }
536  if (setrlimit(RLIMIT_CPU, &rl) != 0) {
537  return false;
538  }
539  s_CpuTimeLimit = max_cpu_time;
540 
541  // Set signal handler for SIGXCPU
542  if (signal(SIGXCPU, s_SignalHandler) == SIG_ERR) {
543  return false;
544  }
545 
546  return true;
547 }
548 
549 #else
550 
551 bool SetCpuTimeLimit(unsigned int max_cpu_time,
552  unsigned int terminate_delay_time,
554  TLimitsPrintParameter parameter)
555 {
556  return false;
557 }
558 
559 #endif //USE_SETCPULIMIT
560 
561 
562 // @deprecated
563 bool SetCpuTimeLimit(size_t max_cpu_time,
565  TLimitsPrintParameter parameter,
566  size_t terminate_delay_time)
567 {
568  return SetCpuTimeLimit((unsigned int)max_cpu_time,
569  (unsigned int)terminate_delay_time,
570  handler, parameter);
571 }
572 
573 
574 /////////////////////////////////////////////////////////////////////////////
575 //
576 /// System information
577 //
578 
579 unsigned int GetCpuCount(void)
580 {
581 #if defined(NCBI_OS_MSWIN)
582  SYSTEM_INFO si;
583  GetSystemInfo(&si);
584  return (unsigned int) si.dwNumberOfProcessors;
585 
586 #elif defined(NCBI_OS_DARWIN)
587  host_basic_info_data_t hinfo;
588  mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
589  kern_return_t rc;
590 
591  rc = host_info(mach_host_self(), HOST_BASIC_INFO,
592  (host_info_t)&hinfo, &hinfo_count);
593 
594  if (rc != KERN_SUCCESS) {
595  return 1;
596  }
597  return hinfo.avail_cpus;
598 
599 #elif defined(NCBI_OS_UNIX)
600  long nproc = 0;
601 # if defined(_SC_NPROC_ONLN)
602  nproc = sysconf(_SC_NPROC_ONLN);
603 # elif defined(_SC_NPROCESSORS_ONLN)
604  nproc = sysconf(_SC_NPROCESSORS_ONLN);
605 # elif defined(NCBI_OS_BSD) || defined(NCBI_OS_DAWRIN)
606  size_t len = sizeof(nproc);
607  int mib[2];
608  mib[0] = CTL_HW;
609  mib[1] = HW_NCPU;
610  if (sysctl(mib, 2, &nproc, &len, 0, 0) < 0 || len != sizeof(nproc))
611  nproc = -1;
612 # endif //UNIX_FLAVOR
613  return nproc <= 0 ? 1 : (unsigned int) nproc;
614 #else
615  return 1;
616 #endif //NCBI_OS_...
617 }
618 
619 
620 bool GetCurrentProcessTimes(double* user_time, double* system_time)
621 {
622 #if defined(NCBI_OS_MSWIN)
623  // Each FILETIME structure contains the number of 100-nanosecond time units
624  FILETIME ft_creation, ft_exit, ft_kernel, ft_user;
625  if (!::GetProcessTimes(GetCurrentProcess(),
626  &ft_creation, &ft_exit, &ft_kernel, &ft_user)) {
627  return false;
628  }
629  if ( system_time ) {
630  *system_time = (ft_kernel.dwLowDateTime +
631  ((Uint8) ft_kernel.dwHighDateTime << 32)) * 1.0e-7;
632  }
633  if ( user_time ) {
634  *user_time = (ft_user.dwLowDateTime +
635  ((Uint8) ft_user.dwHighDateTime << 32)) * 1.0e-7;
636  }
637 
638 #elif defined(NCBI_OS_UNIX)
639 
640  tms buf;
641  clock_t t = times(&buf);
642  if ( t == (clock_t)(-1) ) {
643  return false;
644  }
645  clock_t tick = sysconf(_SC_CLK_TCK);
646 #if defined(CLK_TCK)
647  if (!tick || tick == (clock_t)(-1))
648  tick = CLK_TCK;
649 #elif defined(CLOCKS_PER_SEC)
650  if (!tick || tick == (clock_t)(-1))
651  tick = CLOCKS_PER_SEC;
652 #endif
653  if (tick == (clock_t)(-1)) {
654  return false;
655  }
656  if ( system_time ) {
657  *system_time = (double)buf.tms_stime / (double)tick;
658  }
659  if ( user_time ) {
660  *user_time = (double)buf.tms_utime / (double)tick;
661  }
662 #endif
663  return true;
664 }
665 
666 
667 
668 /////////////////////////////////////////////////////////////////////////////
669 //
670 // Memory utilities
671 //
672 
673 unsigned long GetVirtualMemoryPageSize(void)
674 {
675  static unsigned long ps = 0;
676 
677  if (!ps) {
678 #if defined(NCBI_OS_MSWIN)
679  SYSTEM_INFO si;
680  GetSystemInfo(&si);
681  ps = (unsigned long) si.dwPageSize;
682 #elif defined(NCBI_OS_UNIX)
683 # if defined(_SC_PAGESIZE)
684 # define NCBI_SC_PAGESIZE _SC_PAGESIZE
685 # elif defined(_SC_PAGE_SIZE)
686 # define NCBI_SC_PAGESIZE _SC_PAGE_SIZE
687 # elif defined(NCBI_SC_PAGESIZE)
688 # undef NCBI_SC_PAGESIZE
689 # endif
690 # ifndef NCBI_SC_PAGESIZE
691  long x = 0;
692 # else
693  long x = sysconf(NCBI_SC_PAGESIZE);
694 # undef NCBI_SC_PAGESIZE
695 # endif
696  if (x <= 0) {
697 # ifdef HAVE_GETPAGESIZE
698  if ((x = getpagesize()) <= 0)
699  return 0;
700 # endif
701  return 0;
702  }
703  ps = x;
704 #endif //NCBI_OS_...
705  }
706  return ps;
707 }
708 
709 
711 {
712  static unsigned long ag = 0;
713 
714  if (!ag) {
715 #if defined(NCBI_OS_MSWIN)
716  SYSTEM_INFO si;
717  GetSystemInfo(&si);
718  ag = (unsigned long) si.dwAllocationGranularity;
719 #else
721 #endif
722  }
723  return ag;
724 }
725 
726 
728 {
729 #if defined(NCBI_OS_MSWIN)
730 
731  MEMORYSTATUSEX st;
732  st.dwLength = sizeof(st);
733  if ( GlobalMemoryStatusEx(&st) ) {
734  return st.ullTotalPhys;
735  }
736 
737 #elif defined(NCBI_OS_UNIX) && defined(_SC_PHYS_PAGES)
738 
739  unsigned long num_pages = sysconf(_SC_PHYS_PAGES);
740  if (long(num_pages) != -1L) {
741  return GetVirtualMemoryPageSize() * Uint8(num_pages);
742  }
743 
744 #elif defined(NCBI_OS_BSD) || defined(NCBI_OS_DARWIN)
745 
746  size_t len;
747  int mib[2];
748 # ifdef HW_MEMSIZE
749  uint64_t physmem;
750  mib[1] = HW_MEMSIZE;
751 # else
752  // Native BSD, may be truncated
753  int physmem;
754  mib[1] = HW_PHYSMEM;
755 # endif //HW_MEMSIZE
756  mib[0] = CTL_HW;
757  len = sizeof(physmem);
758  if (sysctl(mib, 2, &physmem, &len, 0, 0) == 0 && len == sizeof(physmem)){
759  return Uint8(physmem);
760  }
761 
762 # ifdef NCBI_OS_DARWIN
763  {
764  // heavier fallback
765  struct vm_statistics vm_stat;
766  mach_port_t my_host = mach_host_self();
767  mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
768  if (host_statistics(my_host, HOST_VM_INFO,
769  (integer_t*) &vm_stat, &count) == KERN_SUCCESS) {
770  return GetVirtualMemoryPageSize() *
771  (Uint8(vm_stat.free_count) + Uint8(vm_stat.active_count) +
772  Uint8(vm_stat.inactive_count) + Uint8(vm_stat.wire_count));
773  }
774  }
775 # endif //NCBI_OS_DARWIN
776 
777 #elif defined(NCBI_OS_IRIX)
778 
779  struct rminfo rmi;
780  if (sysmp(MP_SAGET, MPSA_RMINFO, &rmi, sizeof(rmi)) >= 0) {
781  return GetVirtualMemoryPageSize() * Uint8(rmi.physmem);
782  }
783 
784 #endif
785 
786  return 0;
787 }
788 
789 
790 bool GetMemoryUsage(size_t* total, size_t* resident, size_t* shared)
791 {
792  size_t scratch;
793  if ( !total ) { total = &scratch; }
794  if ( !resident ) { resident = &scratch; }
795  if ( !shared ) { shared = &scratch; }
796 #if defined(NCBI_OS_MSWIN)
797  try {
798  // Load PSAPI dynamic library -- it should exist on MS-Win NT/2000/XP
799  CDll psapi_dll("psapi.dll", CDll::eLoadNow, CDll::eAutoUnload);
800  BOOL (STDMETHODCALLTYPE FAR * dllGetProcessMemoryInfo)
801  (HANDLE process, SProcessMemoryCounters& counters, DWORD size) = 0;
802  dllGetProcessMemoryInfo
803  = psapi_dll.GetEntryPoint_Func("GetProcessMemoryInfo",
804  &dllGetProcessMemoryInfo);
805  if (dllGetProcessMemoryInfo) {
806  SProcessMemoryCounters counters;
807  dllGetProcessMemoryInfo(GetCurrentProcess(), counters,
808  sizeof(counters));
809  *total = counters.quota_paged_pool_usage +
810  counters.quota_nonpaged_pool_usage;
811  *resident = counters.working_set_size;
812  *shared = 0;
813  return true;
814  }
815  } catch (CException) {
816  // Just catch all exceptions from CDll
817  }
818 #elif defined(NCBI_OS_LINUX)
819  CNcbiIfstream statm("/proc/self/statm");
820  if (statm) {
821  unsigned long page_size = GetVirtualMemoryPageSize();
822  statm >> *total >> *resident >> *shared;
823  *total *= page_size;
824  *resident *= page_size;
825  *shared *= page_size;
826  return true;
827  }
828 #elif defined(NCBI_OS_SOLARIS)
829  Int8 len = CFile("/proc/self/as").GetLength();
830  if (len > 0) {
831  *total = (size_t) len;
832  *resident = (size_t) len; // conservative estimate
833  *shared = 0; // does this info exist anywhere?
834  return true;
835  }
836 #elif defined(HAVE_GETRUSAGE)
837 # define _DIV0(a, b) ((a) / ((b) ? (b) : 1))
838  // BIG FAT NOTE: getrusage() seems to use different size units
839  struct rusage ru;
840  memset(&ru, '\0', sizeof(ru));
841  if (getrusage(RUSAGE_SELF, &ru) == 0 && ru.ru_maxrss > 0) {
842  struct tms t;
843  memset(&t, '\0', sizeof(t));
844  if (times(&t) != (clock_t)(-1)) {
845  clock_t ticks = t.tms_utime + t.tms_stime;
846  *resident = _DIV0(ru.ru_idrss, ticks);
847  *shared = _DIV0(ru.ru_ixrss, ticks);
848  *total = _DIV0(ru.ru_ixrss + ru.ru_idrss + ru.ru_isrss, ticks);
849 # ifdef NCBI_OS_DARWIN
850  if (*total > 0)
851 # endif
852  return true;
853  }
854  }
855 # undef _DIV0
856 # ifdef NCBI_OS_DARWIN
857 # ifdef MACH_TASK_BASIC_INFO
858  task_flavor_t flavor = MACH_TASK_BASIC_INFO;
859  struct mach_task_basic_info t_info;
860  mach_msg_type_number_t t_info_count = MACH_TASK_BASIC_INFO_COUNT;
861 # else
862  task_flavor_t flavor = TASK_BASIC_INFO;
863  struct task_basic_info t_info;
864  mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
865 # endif
866  if (task_info(mach_task_self(), flavor, (task_info_t)&t_info,
867  &t_info_count) == KERN_SUCCESS) {
868  *total = *resident = t_info.resident_size;
869  *shared = 0; // unavailable, even with mach_task_basic_info
870  return true;
871  }
872 # endif
873 #endif
874  return false;
875 }
876 
877 
878 #ifndef HAVE_MADVISE
879 bool MemoryAdvise(void*, size_t, EMemoryAdvise) {
880  return false;
881 }
882 #else //HAVE_MADVISE
883 bool MemoryAdvise(void* addr, size_t len, EMemoryAdvise advise)
884 {
885  if ( !addr /*|| !len*/ ) {
886  ERR_POST_X(11, "Memory address is not specified");
888  return false;
889  }
890  int adv;
891  switch (advise) {
892  case eMADV_Normal:
893  adv = MADV_NORMAL; break;
894  case eMADV_Random:
895  adv = MADV_RANDOM; break;
896  case eMADV_Sequential:
897  adv = MADV_SEQUENTIAL; break;
898  case eMADV_WillNeed:
899  adv = MADV_WILLNEED; break;
900  case eMADV_DontNeed:
901  adv = MADV_DONTNEED; break;
902  case eMADV_DontFork:
903  #if defined(MADV_DONTFORK)
904  adv = MADV_DONTFORK;
905  break;
906  #else
907  ERR_POST_X_ONCE(12, Warning << "MADV_DONTFORK not supported");
909  return false;
910  #endif
911  case eMADV_DoFork:
912  #if defined(MADV_DOFORK)
913  adv = MADV_DOFORK;
914  break;
915  #else
916  ERR_POST_X_ONCE(12, Warning << "MADV_DOTFORK not supported");
918  return false;
919  #endif
920  case eMADV_Mergeable:
921  #if defined(MADV_MERGEABLE)
922  adv = MADV_MERGEABLE;
923  break;
924  #else
925  ERR_POST_X_ONCE(12, Warning << "MADV_MERGEABLE not supported");
927  return false;
928  #endif
929  case eMADV_Unmergeable:
930  #if defined(MADV_UNMERGEABLE)
931  adv = MADV_UNMERGEABLE;
932  break;
933  #else
934  ERR_POST_X_ONCE(12, Warning << "MADV_UNMERGEABLE not supported");
936  return false;
937  #endif
938  default:
939  _TROUBLE;
940  return false;
941  }
942  // Conversion type of "addr" to char* -- Sun Solaris fix
943  if ( madvise((char*) addr, len, adv) != 0 ) {
944  int x_errno = errno; \
945  ERR_POST_X(13, "madvise() failed: " <<
946  _T_STDSTRING(NcbiSys_strerror(x_errno)));
947  CNcbiError::SetErrno(errno = x_errno);
948  return false;
949  }
950  return true;
951 }
952 #endif //HAVE_MADVISE
953 
954 
955 
956 /////////////////////////////////////////////////////////////////////////////
957 //
958 // Sleep
959 //
960 
961 void SleepMicroSec(unsigned long mc_sec, EInterruptOnSignal onsignal)
962 {
963 #if defined(NCBI_OS_MSWIN)
964 
965  // Unlike some of its (buggy) Unix counterparts, MS-Win's Sleep() is safe
966  // to use with 0, which causes the current thread to sleep at most until
967  // the end of the current timeslice (and only if the CPU is not idle).
968  static const unsigned long kMicroSecondsPerMilliSecond
970  Sleep((mc_sec + (kMicroSecondsPerMilliSecond / 2))
971  / kMicroSecondsPerMilliSecond);
972 
973 #elif defined(NCBI_OS_UNIX)
974 
975 # if defined(HAVE_NANOSLEEP)
976  struct timespec delay, unslept;
977  memset(&unslept, 0, sizeof(unslept));
978  delay.tv_sec = mc_sec / kMicroSecondsPerSecond;
979  delay.tv_nsec = ((mc_sec % kMicroSecondsPerSecond)
981  while (nanosleep(&delay, &unslept) < 0) {
982  if (errno != EINTR || onsignal == eInterruptOnSignal)
983  break;
984  delay = unslept;
985  memset(&unslept, 0, sizeof(unslept));
986  }
987 # elif defined(HAVE_USLEEP)
988  unsigned int sec = mc_sec / kMicroSecondsPerSecond;
989  unsigned int usec = mc_sec % kMicroSecondsPerSecond;
990  if (sec) {
991  while ((sec = sleep(sec)) > 0) {
992  if (onsignal == eInterruptOnSignal)
993  return;
994  }
995  }
996  // usleep() detects errors (such as EINTR) but can't tell unslept time :-/
997  usleep(usec);
998 # else
999  // Portable but ugly.
1000  // Most implementations of select() do not modify timeout to reflect
1001  // the amount of time unslept; but some (e.g. Linux) do. Also, on
1002  // some platforms it can be interrupted by a signal, but not on others.
1003  // OTOH, we don't want to sandwich this with gettimeofday(), either.
1004  struct timeval delay;
1005  delay.tv_sec = mc_sec / kMicroSecondsPerSecond;
1006  delay.tv_usec = mc_sec % kMicroSecondsPerSecond;
1007  while (select(0, (fd_set*) 0, (fd_set*) 0, (fd_set*) 0, &delay) < 0) {
1008 # ifdef SELECT_UPDATES_TIMEOUT
1009  if (errno != EINTR || onsignal == eInterruptOnSignal)
1010 # endif
1011  break;
1012  }
1013 # endif //HAVE FINE SLEEP API
1014 
1015 #endif //NCBI_OS_...
1016 }
1017 
1018 
1019 void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal)
1020 {
1021 #ifdef NCBI_OS_MSWIN
1022  Sleep(ml_sec);
1023 #else
1025  onsignal);
1026 #endif //NCBI_OS_MSWIN
1027 }
1028 
1029 
1030 void SleepSec(unsigned long sec, EInterruptOnSignal onsignal)
1031 {
1032  SleepMicroSec(sec * kMicroSecondsPerSecond, onsignal);
1033 }
1034 
1035 
1036 
1037 /////////////////////////////////////////////////////////////////////////////
1038 ///
1039 /// Suppress Diagnostic Popup Messages (all MS-Win specific)
1040 ///
1041 
1042 #ifdef NCBI_OS_MSWIN
1043 
1044 static bool s_EnableSuppressSystemMessageBox = true;
1045 static bool s_DoneSuppressSystemMessageBox = false;
1046 static bool s_SuppressedDebugSystemMessageBox = false;
1047 
1048 // Handler for "Unhandled" exceptions
1049 static LONG CALLBACK _SEH_Handler(EXCEPTION_POINTERS* ep)
1050 {
1051  // Always terminate a program
1052  return EXCEPTION_EXECUTE_HANDLER;
1053 }
1054 
1055 #endif //NCBI_OS_MSWIN
1056 
1058 {
1059 #ifdef NCBI_OS_MSWIN
1060  if ( !s_EnableSuppressSystemMessageBox ) {
1061  return;
1062  }
1063  // System errors
1064  if ((mode & fSuppress_System) == fSuppress_System ) {
1065  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
1066  SEM_NOOPENFILEERRORBOX);
1067  }
1068  // Runtime library
1069  if ( (mode & fSuppress_Runtime) == fSuppress_Runtime ) {
1070  _set_error_mode(_OUT_TO_STDERR);
1071  }
1072  // Debug library
1073  if ( !IsDebuggerPresent() ) {
1074  if ( (mode & fSuppress_Debug) == fSuppress_Debug ) {
1075  _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
1076  _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
1077  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
1078  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
1079  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
1080  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
1081  s_SuppressedDebugSystemMessageBox = true;
1082  }
1083  }
1084  // Exceptions
1085  if ( (mode & fSuppress_Exception) == fSuppress_Exception ) {
1086  SetUnhandledExceptionFilter(_SEH_Handler);
1087  }
1088  s_DoneSuppressSystemMessageBox = true;
1089 
1090 #else
1091  // dummy, to avoid compilation warning
1092  mode = 0;
1093 
1094 #endif
1095 }
1096 
1097 
1099 {
1100 #ifdef NCBI_OS_MSWIN
1101  if ( s_DoneSuppressSystemMessageBox ) {
1102  ERR_POST_X(9, Critical << "SuppressSystemMessageBox() already called");
1103  }
1104  s_EnableSuppressSystemMessageBox = false;
1105 #endif //NCBI_OS_MSWIN
1106 }
1107 
1108 
1110 {
1111 #ifdef NCBI_OS_MSWIN
1112  return s_DoneSuppressSystemMessageBox &&
1114 #else
1115  return false;
1116 #endif //NCBI_OS_MSWIN
1117 }
1118 
1119 
1120 
1121 extern int GetProcessFDCount(int* soft_limit, int* hard_limit)
1122 {
1123 #ifdef NCBI_OS_UNIX
1124  int fd_count = 0;
1125  struct dirent* dp;
1126 
1127  rlim_t cur_limit = -1;
1128  rlim_t max_limit = -1;
1129 
1130  struct rlimit rlim;
1131  if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
1132  cur_limit = rlim.rlim_cur;
1133  max_limit = rlim.rlim_max;
1134  } else {
1135  // fallback to sysconf
1136  ERR_POST_ONCE(Warning << "getrlimit(RLIMIT_NOFILE, ...) call failed. "
1137  "Using sysconf(_SC_OPEN_MAX) instead.");
1138  cur_limit = static_cast<rlim_t>(sysconf(_SC_OPEN_MAX));
1139  }
1140 
1141  DIR* dir = opendir("/proc/self/fd/");
1142  if (dir) {
1143  while ((dp = readdir(dir)) != NULL)
1144  ++fd_count;
1145  closedir(dir);
1146  fd_count -= 3; // '.', '..' and the one for 'opendir'
1147  if (fd_count < 0)
1148  fd_count = -1;
1149  } else {
1150  // Fallback to analysis via looping over all fds
1151  if (cur_limit > 0) {
1152  int max_fd = static_cast<int>(cur_limit);
1153  if (cur_limit > INT_MAX)
1154  max_fd = INT_MAX;
1155  for (int fd = 0; fd < max_fd; ++fd) {
1156  if (fcntl(fd, F_GETFD, 0) == -1) {
1157  if (errno == EBADF)
1158  continue;
1159  }
1160  ++fd_count;
1161  }
1162  } else {
1163  fd_count = -1;
1164  }
1165  }
1166 
1167  if (soft_limit || hard_limit) {
1168  if (soft_limit) {
1169  if (cur_limit > INT_MAX)
1170  *soft_limit = INT_MAX;
1171  else
1172  *soft_limit = static_cast<int>(cur_limit);
1173  }
1174  if (hard_limit) {
1175  if (max_limit > INT_MAX)
1176  *hard_limit = INT_MAX;
1177  else
1178  *hard_limit = static_cast<int>(max_limit);
1179  }
1180  }
1181  return fd_count;
1182 #else
1183  if (soft_limit)
1184  *soft_limit = -1;
1185  if (hard_limit)
1186  *hard_limit = -1;
1187  return -1;
1188 #endif //NCBI_OS_UNIX
1189 }
1190 
1191 
1192 extern int GetProcessThreadCount(void)
1193 {
1194 #ifdef NCBI_OS_LINUX
1195  int thread_count = 0;
1196  struct dirent* dp;
1197 
1198  DIR* dir = opendir("/proc/self/task/");
1199  if (dir) {
1200  while ((dp = readdir(dir)) != NULL)
1201  ++thread_count;
1202  closedir(dir);
1203  thread_count -= 2; // '.' and '..'
1204  if (thread_count <= 0)
1205  thread_count = -1;
1206  return thread_count;
1207  }
1208  return -1;
1209 #else
1210  return -1;
1211 #endif //NCBI_OS_LINUX
1212 }
1213 
1214 
1216 {
1217 #if defined(NCBI_OS_UNIX)
1218  return CUnixFeature::GetUserNameByUID(geteuid());
1219 #elif defined(NCBI_OS_MSWIN)
1220  return CWinSecurity::GetUserName();
1221 #else
1222  return string();
1223 #endif
1224 }
1225 
1226 
static string GetUserName(void)
Get name of the current user.
time_t GetTimeT(void) const
Get time in time_t format.
Definition: ncbitime.cpp:1399
void SuppressSystemMessageBox(TSuppressSystemMessageBox mode)
Suppress popup messages on execution errors.
char * buf
const long kMicroSecondsPerSecond
Number of microseconds in one second.
Definition: ncbitime.hpp:88
Do inherit across fork() – by default.
#define ERR_POST_ONCE(message)
Error posting only once during program execution.
Definition: ncbidiag.hpp:596
CSafeStatic<>::
bool GetCurrentProcessTimes(double *user_time, double *system_time)
[UNIX & Windows] Get current process execution times.
bool SetMemoryLimit(size_t max_size, TLimitsPrintHandler handler, TLimitsPrintParameter parameter)
[UNIX only] Set memory limit.
static void SetFormat(const CTimeFormat &fmt)
Set the current time format.
Definition: ncbitime.cpp:1271
Don't inherit across fork()
unsigned NCBI_INT8_TYPE Uint8
Unsigned 8 byte sized integer.
Definition: ncbitype.h:146
static size_t s_MemoryLimitHard
#define _TROUBLE
static void handler(int)
Expect random page references.
Unhandled exceptions.
Uint8 GetPhysicalMemorySize(void)
[UNIX & Windows] Return the amount of physical memory available in the system.
bool SetMemoryLimitSoft(size_t max_size, TLimitsPrintHandler handler, TLimitsPrintParameter parameter)
[UNIX only] Set soft memory limit.
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1008
Normal exit.
Definition: ncbi_system.hpp:60
CTime & AddSecond(TSeconds seconds=1, EDaylight adl=eDaylightDefault)
Add specified seconds.
Definition: ncbitime.cpp:1862
Expect sequential page references.
const long kNanoSecondsPerSecond
Number of nanoseconds in one second.
Definition: ncbitime.hpp:83
CDll –.
Definition: ncbidll.hpp:106
static void s_SignalHandler(int sig)
string
Definition: cgiapp.hpp:498
#define NcbiSys_strerror
Definition: ncbisys.hpp:79
System errors.
signed NCBI_INT8_TYPE Int8
Signed 8 byte sized integer.
Definition: ncbitype.h:143
#define BOOL
Definition: odbcinst.h:18
ELimitsExitCode
Process limits.
Definition: ncbi_system.hpp:59
#define NULL
Definition: ncbistd.hpp:225
KSM may not merge identical pages – by default.
static TLimitsPrintHandler s_PrintHandler
#define _DEBUG_ARG(arg)
Definition: ncbidbg.hpp:132
CTime & SetCurrent(void)
Make the time current in the presently active time zone.
Definition: ncbitime.hpp:2256
void * TLimitsPrintParameter
Type of parameter for print handler.
Definition: ncbi_system.hpp:66
Static variables safety - create on demand, destroy on application termination.
static TLimitsPrintParameter s_PrintHandlerParam
string GetProcessUserName(void)
Get process owner actual user name, doesn't use environment as it can be changed. ...
#define _VERIFY(expr)
Definition: ncbidbg.hpp:159
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:544
Define class Dll and for Portable DLL handling.
void SleepMicroSec(unsigned long mc_sec, EInterruptOnSignal onsignal)
SIZE_T quota_peak_nonpaged_pool_usage
static ELimitsExitCode s_ExitCode
EInterruptOnSignal
Interrupt on signal mode.
Definition: ncbimisc.hpp:152
int GetProcessThreadCount(void)
[Linux only] Provides the number of threads in the current process.
DEFINE_STATIC_FAST_MUTEX(s_ExitHandler_Mutex)
bool IsSuppressedDebugSystemMessageBox(void)
Check if system message box has been suppressed for debug library.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
static const char si[8][64]
Definition: des.c:152
unsigned long GetVirtualMemoryPageSize(void)
[UNIX & Windows] Return virtual memory page size.
unsigned int DWORD
Definition: sqltypes.h:98
bool MemoryAdvise(void *addr, size_t len, EMemoryAdvise advise)
[UNIX only] Advise on memory usage for specified memory region.
static LONG CALLBACK _SEH_Handler(EXCEPTION_POINTERS *ep)
Defines NCBI C++ Toolkit portable error codes.
mdb_mode_t mode
Definition: lmdb++.h:46
CFile –.
Definition: ncbifile.hpp:1574
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal)
#define CLOCKS_PER_SEC
Definition: pcretest.c:161
TFunc GetEntryPoint_Func(const string &name, TFunc *func)
Get DLLs entry point (function).
Definition: ncbidll.hpp:273
static void s_ExitHandler(void)
#define _T_STDSTRING(x)
Definition: ncbistr.hpp:177
static string GetUserNameByUID(uid_t uid)
Look up user name by given numeric user ID.
static void s_NewHandler(void)
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Definition: ncbitime.cpp:1515
int size
static char * s_ReserveMemory
int TSuppressSystemMessageBox
Binary OR of "ESuppressSystemMessageBox".
bool GetMemoryUsage(size_t *total, size_t *resident, size_t *shared)
[UNIX & Windows] Return current memory usage, in bytes.
No further special treatment – by default.
static bool s_SetExitHandler(TLimitsPrintHandler handler, TLimitsPrintParameter parameter)
KSM may merge identical pages.
Int8 GetLength(void) const
Get size of file.
Definition: ncbifile.cpp:3160
#define FAR
Definition: ncbistd.hpp:278
CTime –.
Definition: ncbitime.hpp:290
static size_t s_CpuTimeLimit
CPU usage limit.
Definition: ncbi_system.hpp:62
unsigned __int64 uint64_t
Definition: stdint.h:136
#define ERR_POST_X_ONCE(err_subcode, message)
Error posting only once during program execution with default error code and given error subcode...
Definition: ncbidiag.hpp:615
static bool s_SuppressedDebugSystemMessageBox
CException –.
Definition: ncbiexpt.hpp:709
void SleepSec(unsigned long sec, EInterruptOnSignal onsignal)
Sleep.
#define HANDLE
An abstraction for a file handle.
Definition: mdb.c:375
Private UNIX specific features.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock, CFileIO, CFileReader, CFileWriter, CFileReaderWriter, CFileException.
static int errno
Definition: dblib.c:54
Defines MS Windows specific private functions and classes.
Multi-threading – mutexes; rw-locks; semaphore.
int len
Cancel operation if interrupted by a signal.
Definition: ncbimisc.hpp:153
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1153
#define NCBI_OS_UNIX
static CSafeStatic< CTime > s_TimeSet
unsigned int GetCpuCount(void)
System information.
bool SetCpuTimeLimit(unsigned int max_cpu_time, unsigned int terminate_delay_time, TLimitsPrintHandler handler, TLimitsPrintParameter parameter)
[UNIX only] Set CPU usage limit.
bool SetHeapLimit(size_t max_size, TLimitsPrintHandler handler, TLimitsPrintParameter parameter)
[UNIX only] Set memory limit.
#define _ASSERT
void Critical(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1020
static void SetErrno(int errno_code)
Set last error using errno code.
Definition: ncbierror.cpp:196
Do not expect access in the near future.
Use current time.
Definition: ncbitime.hpp:295
bool SetMemoryLimitHard(size_t max_size, TLimitsPrintHandler handler, TLimitsPrintParameter parameter)
[UNIX only] Set hard memory limit.
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:245
exit(2)
static const unsigned char ct[6 *3][64]
Definition: gcm.c:588
void(* TLimitsPrintHandler)(ELimitsExitCode, size_t, CTime &, TLimitsPrintParameter)
Type of handler for printing a dump information after generating any limitation event.
Definition: ncbi_system.hpp:80
static bool s_ExitHandlerIsSet
static size_t s_MemoryLimitSoft
EMemoryAdvise
What type of data access pattern will be used for specified memory region.
Runtime library.
static void Set(ECode code)
Set last error using native error code enum.
Definition: ncbierror.cpp:166
const long kMilliSecondsPerSecond
Number milliseconds in one second.
Definition: ncbitime.hpp:93
void DisableSuppressSystemMessageBox(void)
Prevent run of SuppressSystemMessageBox().
SIZE_T quota_peak_paged_pool_usage
Definition: ncbi_system.cpp:99
int GetProcessFDCount(int *soft_limit, int *hard_limit)
[UNIX only] Provides the process consumed file descriptors count as well as system wide file descript...
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
Expect access in the near future.
unsigned long GetVirtualMemoryAllocationGranularity(void)
[UNIX & Windows] Return size of an allocation unit (usually it is a multiple of page size)...
Memory limit.
Definition: ncbi_system.hpp:61
static uschar * buffer
Definition: pcretest.c:187
T & Get(void)
Create the variable if not created yet, return the reference.
Debug library.
#define CALLBACK
Definition: sqltypes.h:65
Modified on Wed Aug 16 06:07:54 2017 by modify_doxy.py rev. 533848