in reply to How to know STDOUT associated with a process pid

Perhaps something with fstat (see POSIX for information) could be worked up? According to my man page for the system version of fstat, you can get the device and inode of a specific file descriptor. Perhaps you could then use that with some of the file test operators to find it on the file system.

Be aware, however, that just because you have an inode does not mean that it is linked into the file system. If you open a file, and then unlink it, you can still write to the file pointed to by that inode without it being available from the file system.

--MidLifeXis

  • Comment on Re: How to know STDOUT associated with a process pid

Replies are listed 'Best First'.
Re^2: How to know STDOUT associated with a process pid
by bgupta (Novice) on Feb 06, 2009 at 18:02 UTC
    If I am understanding it correctly this would require a file descriptor of the output file, since I am invoking the perl code from unix command line or a shell script , how can I get the file descriptor of the filename which will be created by the redirected output of the invoked perl program inside that perl program ? The perl script has been invoked via shell scripts at several places and I am going to modify the perl script to know where its output is being redirected by invoking it through unix command line( or shell script ). Please clarify if I am missing something.

      STDOUT can get you a file descriptor of some sort, right?

      It has been many years since I have done this, but the -t test in the shell can tell if it is attached to a file or a pty, so I would guess that you can get to the inode (if applicable) attached to the STDOUT as well.

      Some of the other responses on this posting also have good ideas, some even with already written solutions (even the negative responses have some good stuff in them if you dig a little). I would pursue the fstat stuff only if the other stuff on this thread didn't pan out. In fact, it would not surprise me if some of the other solutions even used fstat behind the scenes.

      Good luck

      --MidLifeXis