//============================================= // Copyright RSAA, 2012 // Written by Ian Price (2012-02-10) //============================================= // // This is a simple command-line app that monitors // GPU device memory usage in an endless loop and // updates a single line in the terminal. // It traps th signals TERM, INT, QUIT HUP and // shutsdown cleanly when any of these signals are // delivered. #include #include #include #include #include #include #include static bool gRun = true; void signalHandler(int signum) { gRun = false; } // rewrites the same line on the terminal by blotting out // the previous line and backspacing to the start of the line // before writing. void writeLine(size_t &lastLineLength, const std::string &str) { size_t lineLen = str.size(); size_t k=0; if (lastLineLength > lineLen) { // first need to blot out the previous line for (k=0; k