From: Vilmos Soti on
Hello,

Is there a way to figure out which one is the active virtual terminal?

I am not interested which terminal I am on (tty tells me that),
but basically I want my program to be able to figure out if it
is running on the active terminal and act accordingly.

Thanks, Vilmos
From: John Reiser on
> Is there a way to figure out which one is the active virtual terminal?

You can try getpgid() and/or getpgrp() to find the process group leader
(the closest ancestor who called setsid()), then examine /proc/PID/fd/*
of that process for likely candidates.

> I am not interested which terminal I am on (tty tells me that),
> but basically I want my program to be able to figure out if it
> is running on the active terminal and act accordingly.

It could be a pty (pseudo tty) instead, and the connection of
that pty to a "real" terminal (or no terminal at all) can vary
over time.

Writing the code so that the behavior depends on such info
often backfires. It's harder to debug, harder to document,
harder to educate users, harder to integrate into pipelines
and collections of processes, etc. Avoid it.

--
From: Vilmos Soti on
John Reiser <jreiserfl(a)comcast.net> writes:

>> Is there a way to figure out which one is the active virtual terminal?
>
> You can try getpgid() and/or getpgrp() to find the process group leader
> (the closest ancestor who called setsid()), then examine /proc/PID/fd/*
> of that process for likely candidates.

Thanks for your time. The solutions is ... fgconsole.

Vilmos