X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBasics%2FMonitoring.cxx;h=85247479c6745946c2c62a3299d6974517f85c18;hb=1bbffef73eeeb5b2a14d8fc7bdf91affdafae664;hp=690490c04046d23a7ea9b3897c48201b408b36d0;hpb=9dd39c3e1305ed2fde91d85194fc543700ced361;p=modules%2Fkernel.git diff --git a/src/Basics/Monitoring.cxx b/src/Basics/Monitoring.cxx index 690490c04..85247479c 100644 --- a/src/Basics/Monitoring.cxx +++ b/src/Basics/Monitoring.cxx @@ -44,14 +44,10 @@ #include #endif -static std::string _out_filename; #ifndef WIN32 -static pid_t pid_of_subprocess = 0; -#endif - -#ifndef WIN32 -static void LaunchMonitoringLinux(const std::string& pyScriptToEvaluate, const std::string& outFileName) +static long LaunchMonitoringLinux(const std::string& pyScriptToEvaluate) { + pid_t pid_of_subprocess = 0; constexpr char PYTHON_EXEC[] = "python3"; pid_t pid = fork(); if (pid == -1) @@ -69,14 +65,14 @@ static void LaunchMonitoringLinux(const std::string& pyScriptToEvaluate, const s { pid_of_subprocess = pid; } + return pid_of_subprocess; } #endif -void SALOME::LaunchMonitoring(const std::string& pyScriptToEvaluate, const std::string& outFileName) +long SALOME::LaunchMonitoring(const std::string& pyScriptToEvaluate) { - _out_filename = outFileName; #ifndef WIN32 - LaunchMonitoringLinux(pyScriptToEvaluate,outFileName); + return LaunchMonitoringLinux(pyScriptToEvaluate); #else throw std::runtime_error("LaunchMonitoring not implemented for Windows !"); #endif @@ -88,7 +84,7 @@ std::vector SALOME::ReadFloatsInFile(const std::string& fileName) if(!inputFile.is_open()) { - std::ostringstream oss; oss << "Impossible to open file \"" << _out_filename<< "\" !"; + std::ostringstream oss; oss << "Impossible to open file \"" << fileName << "\" !"; throw std::runtime_error( oss.str() ); } std::vector ret; @@ -114,25 +110,17 @@ std::vector SALOME::ReadFloatsInFile(const std::string& fileName) } #ifndef WIN32 -static std::vector StopMonitoringLinux() +static void StopMonitoringLinux(long pid) { + pid_t pid_of_subprocess = (pid_t) pid; kill( pid_of_subprocess, SIGTERM ); - std::vector ret; - try - { - ret = SALOME::ReadFloatsInFile( _out_filename ); - } - catch(std::exception& e) { } - pid_of_subprocess = 0; - _out_filename.clear(); - return ret; } #endif -std::vector SALOME::StopMonitoring() +void SALOME::StopMonitoring(long pid) { #ifndef WIN32 - return StopMonitoringLinux(); + return StopMonitoringLinux( pid ); #else throw std::runtime_error("StopMonitoring not implemented for Windows !"); #endif