[buug] Linux hacking question

Ian Zimmerman itz at speakeasy.org
Fri May 31 23:43:48 PDT 2002


Hi, how can I get the ID of the foreground process group for a
terminal?  Assume I am running with root privileges, but the terminal
is _not_ my controlling terminal (in fact I am a daemon, so I have no
controlling terminal).  I tried 

  pid_t foreground;

  ioctl(terminal_fd, TIOCGPGRP, &foreground);

but it fails with ENOTTY, and in linux/drivers/char/tty_io.c I find
this code:

tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t *arg)
{
	/*
	 * (tty == real_tty) is a cheap way of
	 * testing if the tty is NOT a master pty.
	 */
	if (tty == real_tty && current->tty != real_tty)
		return -ENOTTY;
	return put_user(real_tty->pgrp, arg);
}

so it's clear it that it fails in my case, root or not.

Suggestions?

-- 
Ian Zimmerman, Oakland, California, U.S.A.
GPG: 433BA087  9C0F 194F 203A 63F7 B1B8  6E5A 8CA3 27DB 433B A087
EngSoc adopts market economy: cheap is wasteful, efficient is expensive.




More information about the buug mailing list