Does a shell automatically connect file descriptors 0, 1 and 2 to its controlling terminal?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-3
down vote

favorite












From The Linux Programming Interface




In an interactive shell, these three file
descriptors 0, 1 and 2 normally refer to the terminal under which the shell is running.





  1. Does "the terminal under which the shell is running" mean the
    controlling terminal of the session to which the interactive shell
    belongs?



    If yes, what if the shell's session doesn't have a controlling terminal?




  2. When the shell is created from its parent process, will the shell automatically create connection betwee file descriptors 0, 1 and 2 and the terminal, in each of
    the following cases (inheritance from the parent process of the shell):



    • if "the terminal under which the shell is running" or the controlling terminal has already been opened at a file descriptor
      which is not 0, 1 and 2?


    • if the file descriptors 0, 1 and 2 have already been connected to a file which is not "the terminal under which the shell is running"
      or the controlling terminal?



  3. What if the shell in the quote is noninteractive?

Thanks.



Btw, just assume "shell" is POSIX or bash.



Related How can we disconnect a file descriptor from any file?







share|improve this question

















  • 1




    The terminal opens FDs 0, 1, and 2 to whichever executable it runs. If the executable happens to be a shell then so be it.
    – Ignacio Vazquez-Abrams
    May 29 at 2:16










  • And if the terminal is connected over a port, like all real terminals used to be, (traditionally) init spawns getty which opens the port and waits for a terminal to connect then execs login which verifies the userid/password and usually (except for a restricted userid) execs a shell -- all with 0,1,2 on the terminal.
    – dave_thompson_085
    May 29 at 3:28















up vote
-3
down vote

favorite












From The Linux Programming Interface




In an interactive shell, these three file
descriptors 0, 1 and 2 normally refer to the terminal under which the shell is running.





  1. Does "the terminal under which the shell is running" mean the
    controlling terminal of the session to which the interactive shell
    belongs?



    If yes, what if the shell's session doesn't have a controlling terminal?




  2. When the shell is created from its parent process, will the shell automatically create connection betwee file descriptors 0, 1 and 2 and the terminal, in each of
    the following cases (inheritance from the parent process of the shell):



    • if "the terminal under which the shell is running" or the controlling terminal has already been opened at a file descriptor
      which is not 0, 1 and 2?


    • if the file descriptors 0, 1 and 2 have already been connected to a file which is not "the terminal under which the shell is running"
      or the controlling terminal?



  3. What if the shell in the quote is noninteractive?

Thanks.



Btw, just assume "shell" is POSIX or bash.



Related How can we disconnect a file descriptor from any file?







share|improve this question

















  • 1




    The terminal opens FDs 0, 1, and 2 to whichever executable it runs. If the executable happens to be a shell then so be it.
    – Ignacio Vazquez-Abrams
    May 29 at 2:16










  • And if the terminal is connected over a port, like all real terminals used to be, (traditionally) init spawns getty which opens the port and waits for a terminal to connect then execs login which verifies the userid/password and usually (except for a restricted userid) execs a shell -- all with 0,1,2 on the terminal.
    – dave_thompson_085
    May 29 at 3:28













up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











From The Linux Programming Interface




In an interactive shell, these three file
descriptors 0, 1 and 2 normally refer to the terminal under which the shell is running.





  1. Does "the terminal under which the shell is running" mean the
    controlling terminal of the session to which the interactive shell
    belongs?



    If yes, what if the shell's session doesn't have a controlling terminal?




  2. When the shell is created from its parent process, will the shell automatically create connection betwee file descriptors 0, 1 and 2 and the terminal, in each of
    the following cases (inheritance from the parent process of the shell):



    • if "the terminal under which the shell is running" or the controlling terminal has already been opened at a file descriptor
      which is not 0, 1 and 2?


    • if the file descriptors 0, 1 and 2 have already been connected to a file which is not "the terminal under which the shell is running"
      or the controlling terminal?



  3. What if the shell in the quote is noninteractive?

Thanks.



Btw, just assume "shell" is POSIX or bash.



Related How can we disconnect a file descriptor from any file?







share|improve this question













From The Linux Programming Interface




In an interactive shell, these three file
descriptors 0, 1 and 2 normally refer to the terminal under which the shell is running.





  1. Does "the terminal under which the shell is running" mean the
    controlling terminal of the session to which the interactive shell
    belongs?



    If yes, what if the shell's session doesn't have a controlling terminal?




  2. When the shell is created from its parent process, will the shell automatically create connection betwee file descriptors 0, 1 and 2 and the terminal, in each of
    the following cases (inheritance from the parent process of the shell):



    • if "the terminal under which the shell is running" or the controlling terminal has already been opened at a file descriptor
      which is not 0, 1 and 2?


    • if the file descriptors 0, 1 and 2 have already been connected to a file which is not "the terminal under which the shell is running"
      or the controlling terminal?



  3. What if the shell in the quote is noninteractive?

Thanks.



Btw, just assume "shell" is POSIX or bash.



Related How can we disconnect a file descriptor from any file?









share|improve this question












share|improve this question




share|improve this question








edited May 29 at 2:55
























asked May 29 at 2:15









Tim

22.6k61222401




22.6k61222401







  • 1




    The terminal opens FDs 0, 1, and 2 to whichever executable it runs. If the executable happens to be a shell then so be it.
    – Ignacio Vazquez-Abrams
    May 29 at 2:16










  • And if the terminal is connected over a port, like all real terminals used to be, (traditionally) init spawns getty which opens the port and waits for a terminal to connect then execs login which verifies the userid/password and usually (except for a restricted userid) execs a shell -- all with 0,1,2 on the terminal.
    – dave_thompson_085
    May 29 at 3:28













  • 1




    The terminal opens FDs 0, 1, and 2 to whichever executable it runs. If the executable happens to be a shell then so be it.
    – Ignacio Vazquez-Abrams
    May 29 at 2:16










  • And if the terminal is connected over a port, like all real terminals used to be, (traditionally) init spawns getty which opens the port and waits for a terminal to connect then execs login which verifies the userid/password and usually (except for a restricted userid) execs a shell -- all with 0,1,2 on the terminal.
    – dave_thompson_085
    May 29 at 3:28








1




1




The terminal opens FDs 0, 1, and 2 to whichever executable it runs. If the executable happens to be a shell then so be it.
– Ignacio Vazquez-Abrams
May 29 at 2:16




The terminal opens FDs 0, 1, and 2 to whichever executable it runs. If the executable happens to be a shell then so be it.
– Ignacio Vazquez-Abrams
May 29 at 2:16












And if the terminal is connected over a port, like all real terminals used to be, (traditionally) init spawns getty which opens the port and waits for a terminal to connect then execs login which verifies the userid/password and usually (except for a restricted userid) execs a shell -- all with 0,1,2 on the terminal.
– dave_thompson_085
May 29 at 3:28





And if the terminal is connected over a port, like all real terminals used to be, (traditionally) init spawns getty which opens the port and waits for a terminal to connect then execs login which verifies the userid/password and usually (except for a restricted userid) execs a shell -- all with 0,1,2 on the terminal.
– dave_thompson_085
May 29 at 3:28











1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










No.



This is done by the various implementations of getty, by open-controlling-tty, by the forked pty-slave-side part of an SSH server, by the forked pty-slave-side part of a GUI terminal emulator, or some such.



And notice that the text quoted has no implication that the shell does this. You have created a whole load of questions based upon a false premise pulled out of thin air.



And you knew that getty does this, because you wrote that it did in "When is the process session led by login started?", written at the same time as this question.



Further reading



  • What is the difference between getty and agetty?

  • "askfirst" getty with systemd ("press enter to activate this console")

  • Jonathan de Boyne Pollard. "Virtual terminal login". nosh Guide. Softwares.

  • Jonathan de Boyne Pollard. "Real terminal login". nosh Guide. Softwares.





share|improve this answer























  • Thanks. I think your nosh is great! I happened to have a problem which nosh's ulimit addresses, and still wonder about how to achieve the similar using regular commands: unix.stackexchange.com/questions/446539/…
    – Tim
    May 29 at 12:29











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446583%2fdoes-a-shell-automatically-connect-file-descriptors-0-1-and-2-to-its-controllin%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










No.



This is done by the various implementations of getty, by open-controlling-tty, by the forked pty-slave-side part of an SSH server, by the forked pty-slave-side part of a GUI terminal emulator, or some such.



And notice that the text quoted has no implication that the shell does this. You have created a whole load of questions based upon a false premise pulled out of thin air.



And you knew that getty does this, because you wrote that it did in "When is the process session led by login started?", written at the same time as this question.



Further reading



  • What is the difference between getty and agetty?

  • "askfirst" getty with systemd ("press enter to activate this console")

  • Jonathan de Boyne Pollard. "Virtual terminal login". nosh Guide. Softwares.

  • Jonathan de Boyne Pollard. "Real terminal login". nosh Guide. Softwares.





share|improve this answer























  • Thanks. I think your nosh is great! I happened to have a problem which nosh's ulimit addresses, and still wonder about how to achieve the similar using regular commands: unix.stackexchange.com/questions/446539/…
    – Tim
    May 29 at 12:29















up vote
3
down vote



accepted










No.



This is done by the various implementations of getty, by open-controlling-tty, by the forked pty-slave-side part of an SSH server, by the forked pty-slave-side part of a GUI terminal emulator, or some such.



And notice that the text quoted has no implication that the shell does this. You have created a whole load of questions based upon a false premise pulled out of thin air.



And you knew that getty does this, because you wrote that it did in "When is the process session led by login started?", written at the same time as this question.



Further reading



  • What is the difference between getty and agetty?

  • "askfirst" getty with systemd ("press enter to activate this console")

  • Jonathan de Boyne Pollard. "Virtual terminal login". nosh Guide. Softwares.

  • Jonathan de Boyne Pollard. "Real terminal login". nosh Guide. Softwares.





share|improve this answer























  • Thanks. I think your nosh is great! I happened to have a problem which nosh's ulimit addresses, and still wonder about how to achieve the similar using regular commands: unix.stackexchange.com/questions/446539/…
    – Tim
    May 29 at 12:29













up vote
3
down vote



accepted







up vote
3
down vote



accepted






No.



This is done by the various implementations of getty, by open-controlling-tty, by the forked pty-slave-side part of an SSH server, by the forked pty-slave-side part of a GUI terminal emulator, or some such.



And notice that the text quoted has no implication that the shell does this. You have created a whole load of questions based upon a false premise pulled out of thin air.



And you knew that getty does this, because you wrote that it did in "When is the process session led by login started?", written at the same time as this question.



Further reading



  • What is the difference between getty and agetty?

  • "askfirst" getty with systemd ("press enter to activate this console")

  • Jonathan de Boyne Pollard. "Virtual terminal login". nosh Guide. Softwares.

  • Jonathan de Boyne Pollard. "Real terminal login". nosh Guide. Softwares.





share|improve this answer















No.



This is done by the various implementations of getty, by open-controlling-tty, by the forked pty-slave-side part of an SSH server, by the forked pty-slave-side part of a GUI terminal emulator, or some such.



And notice that the text quoted has no implication that the shell does this. You have created a whole load of questions based upon a false premise pulled out of thin air.



And you knew that getty does this, because you wrote that it did in "When is the process session led by login started?", written at the same time as this question.



Further reading



  • What is the difference between getty and agetty?

  • "askfirst" getty with systemd ("press enter to activate this console")

  • Jonathan de Boyne Pollard. "Virtual terminal login". nosh Guide. Softwares.

  • Jonathan de Boyne Pollard. "Real terminal login". nosh Guide. Softwares.






share|improve this answer















share|improve this answer



share|improve this answer








edited May 29 at 7:17


























answered May 29 at 7:10









JdeBP

28k459133




28k459133











  • Thanks. I think your nosh is great! I happened to have a problem which nosh's ulimit addresses, and still wonder about how to achieve the similar using regular commands: unix.stackexchange.com/questions/446539/…
    – Tim
    May 29 at 12:29

















  • Thanks. I think your nosh is great! I happened to have a problem which nosh's ulimit addresses, and still wonder about how to achieve the similar using regular commands: unix.stackexchange.com/questions/446539/…
    – Tim
    May 29 at 12:29
















Thanks. I think your nosh is great! I happened to have a problem which nosh's ulimit addresses, and still wonder about how to achieve the similar using regular commands: unix.stackexchange.com/questions/446539/…
– Tim
May 29 at 12:29





Thanks. I think your nosh is great! I happened to have a problem which nosh's ulimit addresses, and still wonder about how to achieve the similar using regular commands: unix.stackexchange.com/questions/446539/…
– Tim
May 29 at 12:29













 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f446583%2fdoes-a-shell-automatically-connect-file-descriptors-0-1-and-2-to-its-controllin%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay