Error run(const std::string& input, ProcessResult* pResult) { // sync child processes don't support pseudoterminal mode #ifndef _WIN32 if (options().pseudoterminal) { return systemError(boost::system::errc::not_supported, ERROR_LOCATION); } #endif // run the process Error error = ChildProcess::run(); if (error) return error; // write input if (!input.empty()) { error = writeToStdin(input, true); if (error) { Error terminateError = terminate(); if (terminateError) LOG_ERROR(terminateError); } } // bail if we aren't waiting for results if (pResult == NULL) return Success(); // read standard out if we didn't have a previous problem if (!error) error = readStdOut(&(pResult->stdOut)); // read standard error if we didn't have a previous problem if (!error) error = readStdErr(&(pResult->stdErr)); // wait on exit and get exit status. note we always need to do this // even if we called terminate due to an earlier error (so we always // reap the child) Error waitError = waitForExit(&(pResult->exitStatus)); if (waitError) { if (!error) error = waitError; else LOG_ERROR(waitError); } // return error status return error; }
void MpiLauncher::destroy(bool force) { pid_t pid=0; int status=0; string pidFile; { ScopedMutexLock lock(_mutex); if (_pid == 0 || _waiting) { throw (InvalidStateException(REL_FILE, __FUNCTION__, __LINE__) << " MPI launcher already destroyed"); } _waiting = true; pid = _pid; status = _status; pidFile = mpi::getLauncherPidFile(_installPath, _queryId, _launchId); if (pid > 0) { if (!force) { scheduleKillTimer(); } else { // kill right away boost::shared_ptr<boost::asio::deadline_timer> dummyTimer; boost::system::error_code dummyErr; handleKillTimeout(dummyTimer, dummyErr); } } if (force) { _inError=true; } } if (pid < 0) { completeLaunch(-pid, pidFile, status); return; } bool rc = waitForExit(pid,&status); assert(rc); rc=rc; { ScopedMutexLock lock(_mutex); if (!_waiting || pid != _pid) { throw InvalidStateException(REL_FILE, __FUNCTION__, __LINE__) << " MPI launcher is corrupted after collecting process exit code"; } _pid = -pid; _status = status; if (_killTimer) { size_t n = _killTimer->cancel(); assert(n<2); n=n; } } completeLaunch(pid, pidFile, status); }
bool MpiLauncher::isRunning() { pid_t pid=0; int status=0; { ScopedMutexLock lock(_mutex); if (_pid<=0) { return false; } pid = _pid; } const bool doNotWait=true; bool rc = waitForExit(pid, &status, doNotWait); if (!rc) { return true; } ScopedMutexLock lock(_mutex); _pid = -pid; _status = status; return false; }
/* OpenGL Hello World ************************* This example draws a yellow rectangle on a blue background. If anything goes wrong it will display a red image and print errors to the console */ int main(int argc, char* argv[]){ //Create an OpenGL window and set up a context with proper debug output // This varies based on platform, we use a couple libraries to do it for us GLFWwindow* window = init(800,600,"OpenGL Hello World"); if(window == nullptr){ //initialization failed return -1; } //set the clear color to a nice blue :) glClearColor(0.1f,0.3f,0.6f,1.0f); //create a simple shader program which tells the GPU how to draw our data //first get the source for the vertex shader GLuint vertexShaderId = glCreateShader(GL_VERTEX_SHADER); std::string vertexSource = readContentsOfFile("simple.vert"); const char* vertexSourcePtr = vertexSource.c_str(); const GLint vertexSourceLength = vertexSource.size(); glShaderSource(vertexShaderId,1,&vertexSourcePtr,&vertexSourceLength); //Give OpenGL the source code //now we can compile it glCompileShader(vertexShaderId); if(!checkCompile(vertexShaderId)){ //check status & get any messages the shader compiler might have generated printf("compiling vertex shader failed :("); waitForExit(window); return -1; } //now the fragment shader GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER); std::string fragmentSource = readContentsOfFile("simple.frag"); const char* fragmentSourcePtr = fragmentSource.c_str(); const GLint fragmentSourceLength = fragmentSource.size(); glShaderSource(fragmentShaderId,1,&fragmentSourcePtr,&fragmentSourceLength); //compile it glCompileShader(fragmentShaderId); if(!checkCompile(fragmentShaderId)){ //check status & get any messages the shader compiler might have generated printf("compiling fragment shader failed :("); waitForExit(window); return -1; } //now we link the shaders together into a program GLuint shaderProgramId = glCreateProgram(); glAttachShader(shaderProgramId,vertexShaderId); glAttachShader(shaderProgramId,fragmentShaderId); //Tell OpenGL what input it should expect to the shader program, in this case one attribute with the position glBindAttribLocation(shaderProgramId,0,"in_Position"); //linking puts everything together so it's ready for use glLinkProgram(shaderProgramId); if(!checkLink(shaderProgramId)){//check status & get any messages the shader compiler might have generated printf("linking shader program failed :("); waitForExit(window); return -1; } //Now we need to make a rectangle for the GPU to draw GLuint vao; GLuint vbo; //create a vertex array object // A vertex array object holds OpenGL state related to vertex data glGenVertexArrays(1,&vao); //create a buffer object to hold some GPU data // we will use it to hold geometry data glGenBuffers(1, &vbo); glBindVertexArray(vao); //make the vertex array object active so we can modify it //bind the buffer object // GL_ARRAY_BUFFER holds per-vertex data, in this case a 3D position glBindBuffer(GL_ARRAY_BUFFER, vbo); //here's some points that make a rectangle, arranged like this: // (1)-----(2) // | / | // | / | // (3)-----(4) // We use a triangle strip so points 2 & 3 are part of both triangles float vertices[] = { -0.5,-0.5, 0.0,//x,y,z 0.5,-0.5, 0.0, -0.5, 0.5, 0.0, 0.5, 0.5, 0.0 }; //This downloads the data to the GPU into the buffer we bound to GL_ARRAY_BUFFER // GL_STATIC_DRAW is a hint to the GPU about what we're going to use the data for // STATIC means that we're going to keep it around for a while and use it multiple times // DRAW means it's data for drawing glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),vertices,GL_STATIC_DRAW); //This tells the GPU how the data is structured. // This is done for each attribute to be passed to the GPU glEnableVertexAttribArray(0); //We're specifying parameter 0, in_Position in the vertex shader glVertexAttribPointer(0, //We're specifying parameter 0, in_Position in the vertex shader 3, //Three components to the member since it's a 3D position, the vec3 type in GLSL GL_FLOAT, //Each component is a float GL_FALSE, //OpenGL can automatically normalize your data if you want 3 * sizeof(float), //This is the offset in the array between the beginning of each attribute // This makes it possible to pack multiple attributes into one buffer. // You can also bind multiple buffers each with different data 0); // This is the offset of the start of data in the buffer //Now that we're done we unbind our Vertex Array Object glBindVertexArray(0); //All our setup is done, now we can enter our normal draw loop while(!glfwWindowShouldClose(window)){ //first poll for events glfwPollEvents(); //clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //tell OpenGL to use the program we made earlier for drawing glUseProgram(shaderProgramId); //use our vertex data declared by the vertex array object for drawing glBindVertexArray(vao); //Draw! glDrawArrays(GL_TRIANGLE_STRIP, //We're using triangle strips 0, //start with the first vertex 4); //draw 4 vertices (all of the ones in our buffer in our case) //finally, update the screen with what we've drawn glfwSwapBuffers(window); } return 0; }
/* * @author: Grzegorz Mirek */ void main() { Application application(std::make_shared<MappingConfiguration>()); application.start(); waitForExit(); application.end(); }