Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

If I start an app with this command:

/path/to/my/command >> /var/log/command.log

And the command doesn't return, is there a way, from another prompt, to see what the STDOUT redirect is set to?

I'm looking for something like either

cat /proc/PID/redirects

or

ps -??? | grep PID

but any method will do.

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

Check out the fildescriptor #1 (stdout) in /proc/$PID/fd/. The kernel represents this file as symbolic link to a file the descriptor is redirected to.

$ readlink -f /proc/20361/fd/1
/tmp/file
share|improve this answer
    
Perfect! Thanks! Can you provide a link or details about the other redirects such as STDERR, ie which numbers they are? –  Rich Jun 27 '11 at 13:30
    
At least on Linux (and I believe on every other known UNIX-like OS) they are 0: stdin, 1: stdout, 2: stderr (standard error). Note there are also C macros defined in <stdio.h>: STD{IN,OUT,ERR}_FILENO. See 'man stdout' for details. –  Petr Uzel Jun 27 '11 at 13:35
add comment

A useful tool to see what files are opened by what processes is lsof. You can point it at a specific process with lsof -p1234, and you'll see mostly the same information as you can get with ls -l /proc/1234/fd under Linux, i.e. what files are opened.

The most useful thing with lsof is going the other way round: lsof /path/to/file tells you what processes are using that file.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.