save error output of a running app
hello,
i started a command, it needs very much time. and i have to save the (error-)output. but i forgot it. is there a way to save the output of a running process? because the process runs over this night and i want to know what did the process do. thx for the help best regards toredo |
Assuming your application uses STDERR, then you should be able to run it like:
Code:
./myapp 2>/tmp/myapp_error.log Code:
./myapp >/tmp/myapp.log 2>&1 cheers |
You can also clear up things and see only STDERR live and have a file log too
Code:
myCommand > /dev/null 2>&1 | tee file.txt |
A known technique is by means of the GNU debugger, gdb. You can redirect file descriptors 1 (standard output) and 2 (standard error) from the terminal to a file and leave the process running to its completion.
Here is an example. First, check the PID of the running process, then use the command: Code:
gdb -p PID Code:
$ gdb -p 11220 And here is a little explanation: a) p creat("/home/alex/foo.stdout",0600) $1 = 3 this creates a file with rw permissions and gdb assigns file descriptor 3 to it. This may differ for you, depending on the actual number of file descriptors kept open by the process. The important thing is that you must use this value in the subsequent commands. b) p dup2(3,1) this duplicates fd 3 to fd 1, actually redirecting the standard output to the newly created file. c) p close(3) this closes the file descriptor 3. Steps a), b), c) are repeated for standard error (you can see the difference in the filename and in the dup2 statement, which redirects fd3 to fd2). d) q quit the gnu debugger and detach the process (you have to answer y to the final question). At this point check the two files and see how they will be populated as soon as the process "spits" some more output/error. Note that no lines of output are lost during the gdb session, since gdb attaches itself to the running process and pick up the standard output and the standard error. I hope this is what you're looking for. |
All times are GMT -5. The time now is 07:20 AM. |