1

In a process session with a controlling terminal,

  • if the controlling process closes the file descriptor of the controlling terminal, does the process session become detached from the controlling terminal, i.e. not have any controlling terminal?

  • What if a non-controlling process in the session closes the file descriptor of the controlling terminal?

Thanks.

4
  • Stephen Kitt actually addressed this in two of Tim's questions in 2018: unix.stackexchange.com/questions/446211 and unix.stackexchange.com/questions/447197 . Commented Jan 4, 2019 at 3:52
  • Do you mean the answers to both questions are no? Commented Jan 4, 2019 at 4:03
  • That is correct the answers to both questions are no. Closing the handles does not disassociate the process from its terminal. The terminal still maintains ownership of the processes created under it, unless forked or nohup ed, or stopped and bg ed. This is maintained through the pid parent hierarchy. Commented Jan 4, 2019 at 4:11
  • That is yet another example of why one should always take comment answers with a large sackful of salt. As can be found in unix.stackexchange.com/questions/446211 , the "unless nohup ed" is yet more incorrect information (obviously so, if one considers what nohup does), and as can be found in unix.stackexchange.com/questions/405755 , so too is "maintained through the pid parent hierarchy". Tim has already asked about stopped/background processes in many questions such as unix.stackexchange.com/questions/490986 and unix.stackexchange.com/questions/396840 . Commented Jan 4, 2019 at 8:53

2 Answers 2

3

libc manual: "… All the processes in a session inherit the controlling terminal from the session leader. A session leader that has control of a terminal is called the controlling process of that terminal. …"

According to typical "daemonize" scenario the only way to get rid of controlling terminal is to create new session. Closing file descriptors wouldn't do that.

2
  • Wouldn't there be a ioctl TIOCNOTTY that is able to detach session from controlling terminal? Commented Jan 4, 2019 at 6:13
  • obsolete: stackoverflow.com/a/8777697/990047 Commented Jan 4, 2019 at 6:21
0

By default the program has no file descriptor associated with a controlling terminal, so there is nothing to close. You can open it, but then closing it has nothing to do with the controlling terminal association.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.