+
+//_________________________________________________________________
+void AliReconstruction::SetStopOnResourcesExcess(Int_t vRSS,Int_t vVMEM)
+{
+ // require checking the resources left and stopping on excess
+ // if 0 : no check is done
+ // if >0 : stop reconstruction if exceeds this value
+ // if <0 : use as margin to system limits
+ //
+ const int kKB2MB = 1024;
+ const int kInfMem = 9999999;
+ //
+ struct rlimit r;
+ int pgSize = getpagesize();
+ //
+ if (vRSS>0) {
+ fMaxRSS = vRSS;
+ AliInfo(Form("Setting max. RSS usage to user value %d MB",fMaxRSS));
+ }
+ else if (vRSS<0) {
+ getrlimit(RLIMIT_RSS,&r);
+ fMaxRSS = r.rlim_max==RLIM_INFINITY ? kInfMem : int(r.rlim_max*pgSize/kKB2MB/kKB2MB) + vRSS;
+ AliInfo(Form("Setting max. RSS usage to system hard limit %d%s MB (%d margin)",fMaxRSS,r.rlim_max==RLIM_INFINITY ? "(inf)":"",-vRSS));
+ }
+ else {AliInfo("No check on RSS memory usage will be applied");}
+ //
+ if (vVMEM>0) {
+ fMaxVMEM = vVMEM;
+ AliInfo(Form("Setting max. VMEM usage to user value %d MB",fMaxVMEM));
+ }
+ else if (vVMEM<0) {
+ getrlimit(RLIMIT_AS,&r);
+ fMaxVMEM = r.rlim_max==RLIM_INFINITY ? kInfMem : int(r.rlim_max*pgSize/kKB2MB/kKB2MB) + vVMEM;
+ AliInfo(Form("Setting max. VMEM usage to system hard limit %d%s MB (%d margin)",fMaxVMEM,r.rlim_max==RLIM_INFINITY ? "(inf)":"",-vVMEM));
+ }
+ else {AliInfo("No check on RSS memory usage will be applied");}
+ //
+}
+
+//_________________________________________________________________
+Bool_t AliReconstruction::HasEnoughResources(int ev)
+{
+ // check if process consumed more than allowed resources
+ const int kKB2MB = 1024;
+ Bool_t res = kTRUE;
+ if (!fMaxRSS && !fMaxVMEM) return res;
+ //
+ ProcInfo_t procInfo;
+ gSystem->GetProcInfo(&procInfo);
+ if (procInfo.fMemResident/kKB2MB > fMaxRSS) res = kFALSE;
+ if (procInfo.fMemVirtual/kKB2MB > fMaxVMEM) res = kFALSE;
+ //
+ if (!res) {
+ AliInfo(Form("Job exceeded allowed limits: RSS:%d (%d) VMEM:%d (%d), will stop",
+ int(procInfo.fMemResident/kKB2MB),fMaxRSS,
+ int(procInfo.fMemVirtual/kKB2MB) ,fMaxVMEM));
+ //
+ gSystem->Exec(Form("if [ -e %s ]; then\nrm %s\nfi\necho %d > %s",fgkStopEvFName,fgkStopEvFName,ev,fgkStopEvFName));
+ fStopped = kTRUE;
+ }
+ return res;
+}