Is there a way to restore/recover nohup to see the output in the console?
I know chances are extremely low, but开发者_C百科 is there a way to see what a nohup-ed process has been outputting recently?
I still have this process open but I've run it with redirecting all output to /dev/null.
So is there a way to recover such process back to console, or is it hopeless :(
Cheers
There is a way but it isn't straight forward, the trick is to use dup2 and depends on the fact that your program is linked against libc (which all c/c++ applications would be, but a java application wouldn't be for example)
- attach to your process using gdb
run the following at the gdb prompt to redirect stdout to /tmp/newfile
$ print dup2(open("/tmp/newfile",0), 1)
run the following to redirect stderr to /tmp/newfile
$ print dup2(open("/tmp/newfile",0), 2)
- detach gdb from your process and your done
What dup2 does is
duplicate a file descriptor This means that both stdout/stderr (1 and 2) and the new file descriptor returned from open can be used interchangeable which will cause all output going to stdout and stderr to go to the file you opened.
精彩评论