Monitoring a child process with TStopWatch

Dear ROOTers,

I am running a process (SPheno) that may hang, and thus would like to kill it when it uses more than a certain amount of time. I have written the following code:

       int pid;
      double lasttime=0;

      if( (pid = fork()) == 0 ){
        system("./SPheno LesHouches.in");
      }
        else{

        TStopwatch timer;
        timer.Start(1);

        while (1) {

          double t = timer.RealTime();
          if( t > lasttime ) lasttime = t;

          if( lasttime > 2 ) {
            TThread::Kill( pid );
            cout << "Killing process.." << endl;
          }
          
          timer.Start(0);
          
        }
        timer.Stop();
}

‘Lasttime’ should help me in estimating the average time needed by the process when it does not hang.
But the quantity ‘lasttime’ is always zero at the end. I think I must be mishandling something, do you see what is wrong ?

Thanks in advance,

cheers,

Xavier

Hi,

In order to get the RealTime, you need to first stop the watch, for example (in TFile::CpProgress): watch.Stop(); Double_t lCopy_time = watch.RealTime(); fprintf(stderr, "| %.02f %% [%.01f MB/s]\r", 100.0*(size?(bytesread/size):1), bytesread/lCopy_time/1048576.); watch.Continue();

Cheers,
Philippe.