0

When reading the Open Group Base Specifications Issue 7, 2018 edition, it says in section 11.1.3 The Controlling Terminal

A terminal may belong to a process as its controlling terminal. Each process of a session that has a controlling terminal has the same controlling terminal. A terminal may be the controlling terminal for at most one session. The controlling terminal for a session is allocated by the session leader in an implementation-defined manner.

I am curious about the meaning of the second sentence "Each process of a session that has a controlling terminal has the same controlling terminal". This seems to imply that there can't be more than one controlling terminal in one session. Yet on Ubuntu desktop I can have two or more gnome terminal windows open at the same time in one session (e.g. when logged in as user with UID=1000) where apparently each terminal is the controlling terminal for it's own process group (and therefore there are more than one controlling terminals in this session). Doesn't that conflict with above statement or is it me who is getting things wrong somewhere?

2 Answers 2

3

I can have two or more gnome terminal windows open at the same time in one session (e.g. when logged in as user with UID=1000)

No, because that's not what the specification means by 'session'.

In the context of signals and controlling terminals, a session is created by calling setsid(3), and is used only as a "super-group" of process groups, for signal delivery purposes.

It has nothing to do with session objects tracked by systemd-logind, nor with X11 SM/ICE sessions, nor with desktop environment sessions (gnome-session &c.), nor with the general English term of "login sessions" that you associate with "processes running as the same UID".

So in other words, the same environment (login session, for lack of a better term) may have as many POSIX tty sessions as it wants – usually the terminal emulator will call setsid() for every window or tab, making sure that each pty corresponds to one POSIX session.

2

Session, according to the Open Group Base Specifications Issue 7, 2018 edition:

A collection of process groups established for job control purposes. Each process group is a member of a session. A process is considered to be a member of the session of which its process group is a member. A newly created process joins the session of its creator. A process can alter its session membership; see setsid(). There can be multiple process groups in the same session.

It's not what you call "session" in the context of Ubuntu desktop. Hence the misunderstanding.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .