[oclug] how to get a process's tty

Francis J. A. Pinteric linuxdoctor at linuxdoctor.biz
Fri Apr 9 06:17:15 EDT 2004


On Thu, 8 Apr 2004 23:24:24 -0400
Roger Messier <en916 at ncf.ca> wrote:

> On Thu, 08 Apr 2004 21:55:04 -0400 "Francis J. A. Pinteric"
> <fja at linuxdoctor.biz> wrote:
> > Look at the /proc/<pid>/fd directory. Using an `ls -l' command on
> > that directory will give you all the file descriptors used by that
> > process. I'll leave it as an exercise for the reader to extract the
> > device name.
> > 
> > It's easy to write a shell script at this point.
> > 
> > >>>--fja->
> 
> Thanks Francis, but since my program runs with my uid, that doesn't
> work for processes owned by users other than me.  The program doesn't
> have read permissions for processes owned by other users.
> 

Hmm, you're right. I wonder how ps does it? You can always track
down the source code for ps and see. Then again, unless you can't use
shell language, you can always try this:

[fja at localhost proc]$ ps | awk -- '{ print $1 " " $2}'
PID TTY
2589 pts/3
21179 pts/3
21180 pts/3


Of course, processes without a controlling terminal would have '?'
printed.

>>>--fja->

>>>--fja->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://tux.oclug.on.ca/pipermail/oclug/attachments/20040409/89f3d511/attachment.bin


More information about the OCLUG mailing list