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.

Tim
  • 101,790
  • Stephen Kitt actually addressed this in two of Tim's questions in 2018: https://unix.stackexchange.com/questions/446211/ and https://unix.stackexchange.com/questions/447197/ . – JdeBP Jan 04 '19 at 03:52
  • Do you mean the answers to both questions are no? – Tim Jan 04 '19 at 04: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. – agone Jan 04 '19 at 04: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 https://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 https://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 https://unix.stackexchange.com/questions/490986/ and https://unix.stackexchange.com/questions/396840/ . – JdeBP Jan 04 '19 at 08:53

2 Answers2

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.

poige
  • 6,231
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.

nert
  • 399