Skip to main content
added 127 characters in body
Source Link
Tim
  • 106.9k
  • 234
  • 651
  • 1.1k

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?

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.

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?

added 9 characters in body
Source Link
Tim
  • 106.9k
  • 234
  • 651
  • 1.1k

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. WillWhen the shell still redirectis created from its parent process, will the shell automatically create connection betwee file descriptors 0, 1 and 2 toand 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.

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. Will the shell still redirect 0, 1 and 2 to the terminal, in each of the following cases:

    • 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.

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.

Source Link
Tim
  • 106.9k
  • 234
  • 651
  • 1.1k

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

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. Will the shell still redirect 0, 1 and 2 to the terminal, in each of the following cases:

    • 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.