Dcoder
Dcoder

Reputation: 379

how to get output of a running nohup process if nohup.out gets deleted

I have a nohup process running on my FreeBSD 8.4 box. Initially I was looking at nohup console messages output through

tail -f nohup.out

But I accidentally deleted nohup.out file. How can I access the console messages now ?

Upvotes: 3

Views: 881

Answers (1)

look
look

Reputation: 677

Its pretty easy actually.

  1. First go back in your command history to find the command you used to start the process. For example, nohup my-long-process.sh & Or if you remember it (very likely), just go to the next step.
  2. Now find the process ID of your process. In this example ps -ef|grep my-long-process
  3. You will see the PID (process ID) and the PPID (parent process ID) right after the name of the user you started the process as. The PID you want is the number on the left. Let's say it is 2919 in this example.
  4. Since the process is still running, you will find a directory called /proc/2919/fd. Here 2919 is the PID you got from the ps command above.
  5. If you list that directory, with ls -l /proc/2919/fd, you will see a link (or two) called 1, 2 etc that point to your deleted file. In fact, the name of the destination file will be /path/to/your/nohup.out (deleted).
  6. You can now tail -f tail -f /proc/2919/fd/1.

Oh, and if you want to see what you missed, you can less that file with less /proc/2919/fd/1

Upvotes: 8

Related Questions