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
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