How to determine what process has a controlling terminal...
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > How to determine what process has a controlling terminal...




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How to determine what process has a controlling terminal...  
K-mart Cashier


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-18-07 06:32 AM

I have the following users on my who list:
kye              p0       85.132.8.116     Tue06AM 13:11 -bash (bash)
casper           p2       frau.triohost.co Thu08PM    43 less -R -E -X
-Q -r -d
cdalten          p4       eecs.berkeley.edu  8:33PM     - w
chocnut          p5       pc8008.temp.co.l  7:06PM     6
/usr/local/bin/real/ly
najib            p6       magnifix.com.my   1:38AM 18:06 mutt
marcotap         p7       dsl-189-133-6-33  8:16PM    17 -bash (bash)


The problem is that some of them have a controlling terminal (ie their
terminal is written to utmp) and some don't (ie there is something like
/ftp/45678 instead of /dev/ttyp4 for example).  What would be the
easiest way to go down the list and determine who has a controlling
terminal and who doesn't?

The only thing I can think of is looping through utmp and seeing if
that user has a terminal number written to utmp. If they do, then have
it print back they have a controlling terminal. If not, then have it
print back they don't have a controlling terminal.

Ideas?

Chad






[ Post a follow-up to this message ]



    Re: How to determine what process has a controlling terminal...  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-18-07 12:28 PM

2007-01-17, 17:41(-08), K-mart Cashier:
> I have the following users on my who list:
> kye              p0       85.132.8.116     Tue06AM 13:11 -bash (bash)
> casper           p2       frau.triohost.co Thu08PM    43 less -R -E -X
> -Q -r -d
> cdalten          p4       eecs.berkeley.edu  8:33PM     - w
> chocnut          p5       pc8008.temp.co.l  7:06PM     6
> /usr/local/bin/real/ly
> najib            p6       magnifix.com.my   1:38AM 18:06 mutt
> marcotap         p7       dsl-189-133-6-33  8:16PM    17 -bash (bash)
>
>
> The problem is that some of them have a controlling terminal (ie their
> terminal is written to utmp)

Controlling terminals are not related to utmp. A controlling
terminal is the terminal that sends you a SIGINT when the user
types CTRL-C and you are in its foreground process group or what
sends you a SIGTTIN when you try to read from it and are not in
its foreground process group.

You can know it with:

tty_of() { # arg: <pid>
if tty=$(ps -p "$1" -o tty=); then
case $tty in
("" | "?") return 1;;
(*) printf '/dev/%s\n' "$tty";;
esac
return 0
fi
return 1
}


--
Stéphane





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:42 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register