Suppose there is a session with multiple processes in it and without a controlling terminal.

When the session leader creates a connection to a controlling terminal,

  • how would the other processes in the same session learn that the session has a controlling terminal and

  • how could they also make use of the controlling terminal?

The reason that I have this question is the following. Usually a process calls setsid() to start a new session and become its leader, and calls open() to connect to a controlling terminal. Then the session leader goes on to fork() child processes, and the children will inherit the file descriptor to the controlling terminal.

I then wonder what if a session already has multiple processes and but has no controlling terminal, and then the leader creates a connection to a controlling terminal, and then what about the other processes in the session.



Any new child the session leader creates after it acquired a controlling terminal will also have that controlling terminal. A controlling terminal is something that is inherited from the parent.

In other words: existing children are not affected.

| improve this answer | |
  • Thanks. But I was asking about the already existing children instead of any future children, when the leader acquires a controlling terminal. – Tim May 29 '18 at 16:33
  • OK, I enhanced the answer. – schily May 29 '18 at 16:50
  • Thanks. What do you mean by " existing children are not affected"? The other processes in the same session are not necessarily children of the session leader. How could the other processes learn that the session has a controlling terminal and also open the controlling terminal as a file descriptor? – Tim Jun 1 '18 at 19:17
  • I suggest use the word "processes" instead of "children " because process parent-child relationship is unrelated to session relationship, although children do inherit these properties from parents. Also when controlling terminal changes, foreground processes would be signald, they can do some action to that, like change their controlling terminal. – 炸鱼薯条德里克 Dec 22 '18 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.