- // get the pid of all ompi-server
- std::set<pid_t> thepids1 = getpidofprogram("ompi-server");
- // launch a new ompi-server
- std::string command;
- command = "ompi-server -r ";
- command += GetenvThreadSafe("OMPI_URI_FILE");
- int status=SystemThreadSafe(command.c_str());
- if(status!=0)
- throw SALOME_Exception("Error when launching ompi-server");
- // get the pid of all ompi-server
- std::set<pid_t> thepids2 = getpidofprogram("ompi-server");
- // my ompi-server is the new one
- std::set<pid_t>::const_iterator it;
- for(it=thepids2.begin();it!=thepids2.end();it++)
- if(thepids1.find(*it) == thepids1.end())
- _pid_mpiServer = *it;
- if(_pid_mpiServer < 0)
- throw SALOME_Exception("Error when getting ompi-server id");
+ // Linux specific code
+ pid_t pid = fork(); // spawn a child process, following code is executed in both processes
+ if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
+ {
+ std::string uriarg = GetenvThreadSafeAsString("OMPI_URI_FILE");
+ execlp( "ompi-server", "ompi-server", "-r", uriarg.c_str(), NULL );
+ throw SALOME_Exception("Error when launching ompi-server"); // execlp failed
+ }
+ else if ( pid < 0 )
+ {
+ throw SALOME_Exception("fork() failed");
+ }
+ else // I'm a parent
+ {
+ //wait(NULL); // wait(?) for a child end
+ _pid_mpiServer = pid;
+ }