The scenario is the following (no code available yet): A linux process runs forever in while(1) loop. The process is implemented in C/C++ (POSIX). The process keeps some data to a std::vector.
myvector.push_back("test1");
myvector.push_back("test1");
myvector.pop_back();
myvector.push_back("test1");
The process runs and modifies the vector. I am looking for a mechanism that will print the vector values when executing the binary with a specific command line argument.
Let’s say that the process called “myprocess” and is running. I want to execute the same binary from a new shell like ./myprocess -debug and print the values of the STL container.
Any idea? What is the best mechanism to do it (ie print the memory of another process)
Typically, you don’t “print the memory of another process”. What you do is send the other process a signal asking it to print out the contents of the vector.
For this, you could use a POSIX signal (e.g.
SIGUSR1).A more flexible approach would be for the process to listen on a named pipe (or a TCP port) and accept commands over it. One such command could be to print out the contents of the vector.