When closing a terminal emulator window, is the last file descriptor of a slave side or master side closed?
Clash Royale CLAN TAG#URR8PPP
The Linux Programming Interface says SIGHUP
is sent to the controlling process of a terminal
When a terminal window is closed on a workstation. This occurs because the
last open file descriptor for the master side of the pseudoterminal associated
with the terminal window is closed.
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides. So when a terminal window is closed, it only means the last open file descriptor for the slave side of the pseudoterminal associated with the terminal window is closed. Why does the quote say the "master" side?
Thanks.
terminal-emulator pseudoterminal
add a comment |
The Linux Programming Interface says SIGHUP
is sent to the controlling process of a terminal
When a terminal window is closed on a workstation. This occurs because the
last open file descriptor for the master side of the pseudoterminal associated
with the terminal window is closed.
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides. So when a terminal window is closed, it only means the last open file descriptor for the slave side of the pseudoterminal associated with the terminal window is closed. Why does the quote say the "master" side?
Thanks.
terminal-emulator pseudoterminal
The terminal emulator program has the master side of the pseudoterminal; when the terminal emulator program exits it can only close the master side. The slave side is open in the child process which runs the shell or whatever program runs in the terminal emulator. How could it be otherwise? Think of a real physical terminal: it has an outside and an inside. For a pseudoterminal, the "ouside" part is called the master and the "inside" part the slave.
– AlexP
Jan 2 at 4:59
It can't have multiple slave side. Think it as a pipe, just a tube with two holes. And the window you see on screen doesn't have any direct relationship with pseudo-terminal devices. It's just the terminal-emulator program is rendering data from the pseudo-terminal devices to an X window (or Wayland window, or DRM device, whatever).
– 炸鱼薯条德里克
Jan 2 at 9:37
Back to your question, closing that window (usually, if you're nit-picking, remember your question about closing window and terminating process?) causes(this logic happens in userspace) the terminal emulator process exit, which is holding the master pty fd, not the slave fd(at least non of the terminal emulator program I know).
– 炸鱼薯条德里克
Jan 2 at 9:46
add a comment |
The Linux Programming Interface says SIGHUP
is sent to the controlling process of a terminal
When a terminal window is closed on a workstation. This occurs because the
last open file descriptor for the master side of the pseudoterminal associated
with the terminal window is closed.
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides. So when a terminal window is closed, it only means the last open file descriptor for the slave side of the pseudoterminal associated with the terminal window is closed. Why does the quote say the "master" side?
Thanks.
terminal-emulator pseudoterminal
The Linux Programming Interface says SIGHUP
is sent to the controlling process of a terminal
When a terminal window is closed on a workstation. This occurs because the
last open file descriptor for the master side of the pseudoterminal associated
with the terminal window is closed.
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides. So when a terminal window is closed, it only means the last open file descriptor for the slave side of the pseudoterminal associated with the terminal window is closed. Why does the quote say the "master" side?
Thanks.
terminal-emulator pseudoterminal
terminal-emulator pseudoterminal
asked Jan 2 at 4:02
TimTim
26.4k75248457
26.4k75248457
The terminal emulator program has the master side of the pseudoterminal; when the terminal emulator program exits it can only close the master side. The slave side is open in the child process which runs the shell or whatever program runs in the terminal emulator. How could it be otherwise? Think of a real physical terminal: it has an outside and an inside. For a pseudoterminal, the "ouside" part is called the master and the "inside" part the slave.
– AlexP
Jan 2 at 4:59
It can't have multiple slave side. Think it as a pipe, just a tube with two holes. And the window you see on screen doesn't have any direct relationship with pseudo-terminal devices. It's just the terminal-emulator program is rendering data from the pseudo-terminal devices to an X window (or Wayland window, or DRM device, whatever).
– 炸鱼薯条德里克
Jan 2 at 9:37
Back to your question, closing that window (usually, if you're nit-picking, remember your question about closing window and terminating process?) causes(this logic happens in userspace) the terminal emulator process exit, which is holding the master pty fd, not the slave fd(at least non of the terminal emulator program I know).
– 炸鱼薯条德里克
Jan 2 at 9:46
add a comment |
The terminal emulator program has the master side of the pseudoterminal; when the terminal emulator program exits it can only close the master side. The slave side is open in the child process which runs the shell or whatever program runs in the terminal emulator. How could it be otherwise? Think of a real physical terminal: it has an outside and an inside. For a pseudoterminal, the "ouside" part is called the master and the "inside" part the slave.
– AlexP
Jan 2 at 4:59
It can't have multiple slave side. Think it as a pipe, just a tube with two holes. And the window you see on screen doesn't have any direct relationship with pseudo-terminal devices. It's just the terminal-emulator program is rendering data from the pseudo-terminal devices to an X window (or Wayland window, or DRM device, whatever).
– 炸鱼薯条德里克
Jan 2 at 9:37
Back to your question, closing that window (usually, if you're nit-picking, remember your question about closing window and terminating process?) causes(this logic happens in userspace) the terminal emulator process exit, which is holding the master pty fd, not the slave fd(at least non of the terminal emulator program I know).
– 炸鱼薯条德里克
Jan 2 at 9:46
The terminal emulator program has the master side of the pseudoterminal; when the terminal emulator program exits it can only close the master side. The slave side is open in the child process which runs the shell or whatever program runs in the terminal emulator. How could it be otherwise? Think of a real physical terminal: it has an outside and an inside. For a pseudoterminal, the "ouside" part is called the master and the "inside" part the slave.
– AlexP
Jan 2 at 4:59
The terminal emulator program has the master side of the pseudoterminal; when the terminal emulator program exits it can only close the master side. The slave side is open in the child process which runs the shell or whatever program runs in the terminal emulator. How could it be otherwise? Think of a real physical terminal: it has an outside and an inside. For a pseudoterminal, the "ouside" part is called the master and the "inside" part the slave.
– AlexP
Jan 2 at 4:59
It can't have multiple slave side. Think it as a pipe, just a tube with two holes. And the window you see on screen doesn't have any direct relationship with pseudo-terminal devices. It's just the terminal-emulator program is rendering data from the pseudo-terminal devices to an X window (or Wayland window, or DRM device, whatever).
– 炸鱼薯条德里克
Jan 2 at 9:37
It can't have multiple slave side. Think it as a pipe, just a tube with two holes. And the window you see on screen doesn't have any direct relationship with pseudo-terminal devices. It's just the terminal-emulator program is rendering data from the pseudo-terminal devices to an X window (or Wayland window, or DRM device, whatever).
– 炸鱼薯条德里克
Jan 2 at 9:37
Back to your question, closing that window (usually, if you're nit-picking, remember your question about closing window and terminating process?) causes(this logic happens in userspace) the terminal emulator process exit, which is holding the master pty fd, not the slave fd(at least non of the terminal emulator program I know).
– 炸鱼薯条德里克
Jan 2 at 9:46
Back to your question, closing that window (usually, if you're nit-picking, remember your question about closing window and terminating process?) causes(this logic happens in userspace) the terminal emulator process exit, which is holding the master pty fd, not the slave fd(at least non of the terminal emulator program I know).
– 炸鱼薯条德里克
Jan 2 at 9:46
add a comment |
1 Answer
1
active
oldest
votes
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides.
A pseudo terminal has always just one master side and one slave side. It's just a bidirectional pipe with some extra ops [1].
A terminal emulator which can open more than one window/tab will also handle more than one pseudo tty master.
As I already explained in another answer, the terminal emulator can do its own thing when the user tries to close the window or one of its tabs; For instance, xterm
will not close the master side of the pty, but will just send a SIGHUP
to the process group of the tty, and only destroy the window (and exit) when the process started in in has exited or it's not able to use itself the master part of the pty anymore (eg. because all handles to its slave side were closed).
[1]. On a SystemV system with STREAMS, those extra ops are modular and have to be "pushed" with ioctl(I_PUSH)
. On Linux and *BSD, they're hardwired. Also, the behavior of ptys is not completely standardized; trying to read from a slave with no master or vice-versa will fail with EIO
on Linux but return 0 (EOF) on FreeBSD.
xterm
doesn't? Why? Wouldn't this cause any problems because processes don't get EIO any more? By the way,xterm
support tabs? Is xterm just getting new version or Is there something wrong with my brain?
– 炸鱼薯条德里克
Jan 2 at 9:52
Wow, I never knew that aboutxterm
. Open anxterm
and runkill -STOP $$
. Then the close button onxterm
does not work. You have to kill the xterm e.g. usingxkill
:-).gnome-terminal
lets you close the window though. @炸鱼薯条德里克 I don't think anyone said anything about xterm and tabs.
– sourcejedi
Jan 2 at 10:13
@炸鱼薯条德里克 I don't think there's any standard that says what a program should do on having its window(s) closed, but pulling the rug from under the stuff running in it is not something that I will appreciate. (eg. I've hackedqemu
to send a power down instead of knocking down the vm on having the sdl window closed).
– mosvy
Jan 2 at 10:29
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491961%2fwhen-closing-a-terminal-emulator-window-is-the-last-file-descriptor-of-a-slave%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides.
A pseudo terminal has always just one master side and one slave side. It's just a bidirectional pipe with some extra ops [1].
A terminal emulator which can open more than one window/tab will also handle more than one pseudo tty master.
As I already explained in another answer, the terminal emulator can do its own thing when the user tries to close the window or one of its tabs; For instance, xterm
will not close the master side of the pty, but will just send a SIGHUP
to the process group of the tty, and only destroy the window (and exit) when the process started in in has exited or it's not able to use itself the master part of the pty anymore (eg. because all handles to its slave side were closed).
[1]. On a SystemV system with STREAMS, those extra ops are modular and have to be "pushed" with ioctl(I_PUSH)
. On Linux and *BSD, they're hardwired. Also, the behavior of ptys is not completely standardized; trying to read from a slave with no master or vice-versa will fail with EIO
on Linux but return 0 (EOF) on FreeBSD.
xterm
doesn't? Why? Wouldn't this cause any problems because processes don't get EIO any more? By the way,xterm
support tabs? Is xterm just getting new version or Is there something wrong with my brain?
– 炸鱼薯条德里克
Jan 2 at 9:52
Wow, I never knew that aboutxterm
. Open anxterm
and runkill -STOP $$
. Then the close button onxterm
does not work. You have to kill the xterm e.g. usingxkill
:-).gnome-terminal
lets you close the window though. @炸鱼薯条德里克 I don't think anyone said anything about xterm and tabs.
– sourcejedi
Jan 2 at 10:13
@炸鱼薯条德里克 I don't think there's any standard that says what a program should do on having its window(s) closed, but pulling the rug from under the stuff running in it is not something that I will appreciate. (eg. I've hackedqemu
to send a power down instead of knocking down the vm on having the sdl window closed).
– mosvy
Jan 2 at 10:29
add a comment |
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides.
A pseudo terminal has always just one master side and one slave side. It's just a bidirectional pipe with some extra ops [1].
A terminal emulator which can open more than one window/tab will also handle more than one pseudo tty master.
As I already explained in another answer, the terminal emulator can do its own thing when the user tries to close the window or one of its tabs; For instance, xterm
will not close the master side of the pty, but will just send a SIGHUP
to the process group of the tty, and only destroy the window (and exit) when the process started in in has exited or it's not able to use itself the master part of the pty anymore (eg. because all handles to its slave side were closed).
[1]. On a SystemV system with STREAMS, those extra ops are modular and have to be "pushed" with ioctl(I_PUSH)
. On Linux and *BSD, they're hardwired. Also, the behavior of ptys is not completely standardized; trying to read from a slave with no master or vice-versa will fail with EIO
on Linux but return 0 (EOF) on FreeBSD.
xterm
doesn't? Why? Wouldn't this cause any problems because processes don't get EIO any more? By the way,xterm
support tabs? Is xterm just getting new version or Is there something wrong with my brain?
– 炸鱼薯条德里克
Jan 2 at 9:52
Wow, I never knew that aboutxterm
. Open anxterm
and runkill -STOP $$
. Then the close button onxterm
does not work. You have to kill the xterm e.g. usingxkill
:-).gnome-terminal
lets you close the window though. @炸鱼薯条德里克 I don't think anyone said anything about xterm and tabs.
– sourcejedi
Jan 2 at 10:13
@炸鱼薯条德里克 I don't think there's any standard that says what a program should do on having its window(s) closed, but pulling the rug from under the stuff running in it is not something that I will appreciate. (eg. I've hackedqemu
to send a power down instead of knocking down the vm on having the sdl window closed).
– mosvy
Jan 2 at 10:29
add a comment |
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides.
A pseudo terminal has always just one master side and one slave side. It's just a bidirectional pipe with some extra ops [1].
A terminal emulator which can open more than one window/tab will also handle more than one pseudo tty master.
As I already explained in another answer, the terminal emulator can do its own thing when the user tries to close the window or one of its tabs; For instance, xterm
will not close the master side of the pty, but will just send a SIGHUP
to the process group of the tty, and only destroy the window (and exit) when the process started in in has exited or it's not able to use itself the master part of the pty anymore (eg. because all handles to its slave side were closed).
[1]. On a SystemV system with STREAMS, those extra ops are modular and have to be "pushed" with ioctl(I_PUSH)
. On Linux and *BSD, they're hardwired. Also, the behavior of ptys is not completely standardized; trying to read from a slave with no master or vice-versa will fail with EIO
on Linux but return 0 (EOF) on FreeBSD.
My understanding is that a terminal window is created for a slave side, and a master side can have multiple slave sides.
A pseudo terminal has always just one master side and one slave side. It's just a bidirectional pipe with some extra ops [1].
A terminal emulator which can open more than one window/tab will also handle more than one pseudo tty master.
As I already explained in another answer, the terminal emulator can do its own thing when the user tries to close the window or one of its tabs; For instance, xterm
will not close the master side of the pty, but will just send a SIGHUP
to the process group of the tty, and only destroy the window (and exit) when the process started in in has exited or it's not able to use itself the master part of the pty anymore (eg. because all handles to its slave side were closed).
[1]. On a SystemV system with STREAMS, those extra ops are modular and have to be "pushed" with ioctl(I_PUSH)
. On Linux and *BSD, they're hardwired. Also, the behavior of ptys is not completely standardized; trying to read from a slave with no master or vice-versa will fail with EIO
on Linux but return 0 (EOF) on FreeBSD.
edited Jan 2 at 10:15
sourcejedi
23.3k437102
23.3k437102
answered Jan 2 at 8:49
mosvymosvy
6,2461425
6,2461425
xterm
doesn't? Why? Wouldn't this cause any problems because processes don't get EIO any more? By the way,xterm
support tabs? Is xterm just getting new version or Is there something wrong with my brain?
– 炸鱼薯条德里克
Jan 2 at 9:52
Wow, I never knew that aboutxterm
. Open anxterm
and runkill -STOP $$
. Then the close button onxterm
does not work. You have to kill the xterm e.g. usingxkill
:-).gnome-terminal
lets you close the window though. @炸鱼薯条德里克 I don't think anyone said anything about xterm and tabs.
– sourcejedi
Jan 2 at 10:13
@炸鱼薯条德里克 I don't think there's any standard that says what a program should do on having its window(s) closed, but pulling the rug from under the stuff running in it is not something that I will appreciate. (eg. I've hackedqemu
to send a power down instead of knocking down the vm on having the sdl window closed).
– mosvy
Jan 2 at 10:29
add a comment |
xterm
doesn't? Why? Wouldn't this cause any problems because processes don't get EIO any more? By the way,xterm
support tabs? Is xterm just getting new version or Is there something wrong with my brain?
– 炸鱼薯条德里克
Jan 2 at 9:52
Wow, I never knew that aboutxterm
. Open anxterm
and runkill -STOP $$
. Then the close button onxterm
does not work. You have to kill the xterm e.g. usingxkill
:-).gnome-terminal
lets you close the window though. @炸鱼薯条德里克 I don't think anyone said anything about xterm and tabs.
– sourcejedi
Jan 2 at 10:13
@炸鱼薯条德里克 I don't think there's any standard that says what a program should do on having its window(s) closed, but pulling the rug from under the stuff running in it is not something that I will appreciate. (eg. I've hackedqemu
to send a power down instead of knocking down the vm on having the sdl window closed).
– mosvy
Jan 2 at 10:29
xterm
doesn't? Why? Wouldn't this cause any problems because processes don't get EIO any more? By the way, xterm
support tabs? Is xterm just getting new version or Is there something wrong with my brain?– 炸鱼薯条德里克
Jan 2 at 9:52
xterm
doesn't? Why? Wouldn't this cause any problems because processes don't get EIO any more? By the way, xterm
support tabs? Is xterm just getting new version or Is there something wrong with my brain?– 炸鱼薯条德里克
Jan 2 at 9:52
Wow, I never knew that about
xterm
. Open an xterm
and run kill -STOP $$
. Then the close button on xterm
does not work. You have to kill the xterm e.g. using xkill
:-). gnome-terminal
lets you close the window though. @炸鱼薯条德里克 I don't think anyone said anything about xterm and tabs.– sourcejedi
Jan 2 at 10:13
Wow, I never knew that about
xterm
. Open an xterm
and run kill -STOP $$
. Then the close button on xterm
does not work. You have to kill the xterm e.g. using xkill
:-). gnome-terminal
lets you close the window though. @炸鱼薯条德里克 I don't think anyone said anything about xterm and tabs.– sourcejedi
Jan 2 at 10:13
@炸鱼薯条德里克 I don't think there's any standard that says what a program should do on having its window(s) closed, but pulling the rug from under the stuff running in it is not something that I will appreciate. (eg. I've hacked
qemu
to send a power down instead of knocking down the vm on having the sdl window closed).– mosvy
Jan 2 at 10:29
@炸鱼薯条德里克 I don't think there's any standard that says what a program should do on having its window(s) closed, but pulling the rug from under the stuff running in it is not something that I will appreciate. (eg. I've hacked
qemu
to send a power down instead of knocking down the vm on having the sdl window closed).– mosvy
Jan 2 at 10:29
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491961%2fwhen-closing-a-terminal-emulator-window-is-the-last-file-descriptor-of-a-slave%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The terminal emulator program has the master side of the pseudoterminal; when the terminal emulator program exits it can only close the master side. The slave side is open in the child process which runs the shell or whatever program runs in the terminal emulator. How could it be otherwise? Think of a real physical terminal: it has an outside and an inside. For a pseudoterminal, the "ouside" part is called the master and the "inside" part the slave.
– AlexP
Jan 2 at 4:59
It can't have multiple slave side. Think it as a pipe, just a tube with two holes. And the window you see on screen doesn't have any direct relationship with pseudo-terminal devices. It's just the terminal-emulator program is rendering data from the pseudo-terminal devices to an X window (or Wayland window, or DRM device, whatever).
– 炸鱼薯条德里克
Jan 2 at 9:37
Back to your question, closing that window (usually, if you're nit-picking, remember your question about closing window and terminating process?) causes(this logic happens in userspace) the terminal emulator process exit, which is holding the master pty fd, not the slave fd(at least non of the terminal emulator program I know).
– 炸鱼薯条德里克
Jan 2 at 9:46