How can we find out the pseudoterminal master and slave from each other?
A pseudoterminal has a pair of master and slave.
How can we find out the master device file from a slave device file (e.g. /etc/pts/3
)? I only find /dev/ptmx
and /dev/pts/ptmx
, but they can't be shared by multiple slaves.
Given one of the processes working on the master and slave, how can we find out the other?
For example, ps
provides information about the controlling tty of each process. Can it be helpful?
Thanks.
linux pseudoterminal
add a comment |
A pseudoterminal has a pair of master and slave.
How can we find out the master device file from a slave device file (e.g. /etc/pts/3
)? I only find /dev/ptmx
and /dev/pts/ptmx
, but they can't be shared by multiple slaves.
Given one of the processes working on the master and slave, how can we find out the other?
For example, ps
provides information about the controlling tty of each process. Can it be helpful?
Thanks.
linux pseudoterminal
2
Possible duplicate of Are all the slaves paired with the same master?
– JdeBP
8 hours ago
add a comment |
A pseudoterminal has a pair of master and slave.
How can we find out the master device file from a slave device file (e.g. /etc/pts/3
)? I only find /dev/ptmx
and /dev/pts/ptmx
, but they can't be shared by multiple slaves.
Given one of the processes working on the master and slave, how can we find out the other?
For example, ps
provides information about the controlling tty of each process. Can it be helpful?
Thanks.
linux pseudoterminal
A pseudoterminal has a pair of master and slave.
How can we find out the master device file from a slave device file (e.g. /etc/pts/3
)? I only find /dev/ptmx
and /dev/pts/ptmx
, but they can't be shared by multiple slaves.
Given one of the processes working on the master and slave, how can we find out the other?
For example, ps
provides information about the controlling tty of each process. Can it be helpful?
Thanks.
linux pseudoterminal
linux pseudoterminal
edited 8 hours ago
Stephen Kitt
164k24366445
164k24366445
asked 9 hours ago
Tim
26.1k74246455
26.1k74246455
2
Possible duplicate of Are all the slaves paired with the same master?
– JdeBP
8 hours ago
add a comment |
2
Possible duplicate of Are all the slaves paired with the same master?
– JdeBP
8 hours ago
2
2
Possible duplicate of Are all the slaves paired with the same master?
– JdeBP
8 hours ago
Possible duplicate of Are all the slaves paired with the same master?
– JdeBP
8 hours ago
add a comment |
2 Answers
2
active
oldest
votes
On Linux, using devpts
, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx
, but there’s no corresponding device node.
See the ptmx
manpage for details.
(With BSD-style pty
s on Linux, there are matching device pairs, such as /dev/ptyp1
and /dev/ttyp1
, respectively on the master and slave side.)
add a comment |
That is one thing that is harder than it should be.
With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index
entry from /proc/PID/fdinfo/FD
. See this commit.
When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx
to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX
to find all processes that hold a handle to the slave pty.
With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3)
on the file descriptor.
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%2f492302%2fhow-can-we-find-out-the-pseudoterminal-master-and-slave-from-each-other%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
On Linux, using devpts
, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx
, but there’s no corresponding device node.
See the ptmx
manpage for details.
(With BSD-style pty
s on Linux, there are matching device pairs, such as /dev/ptyp1
and /dev/ttyp1
, respectively on the master and slave side.)
add a comment |
On Linux, using devpts
, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx
, but there’s no corresponding device node.
See the ptmx
manpage for details.
(With BSD-style pty
s on Linux, there are matching device pairs, such as /dev/ptyp1
and /dev/ttyp1
, respectively on the master and slave side.)
add a comment |
On Linux, using devpts
, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx
, but there’s no corresponding device node.
See the ptmx
manpage for details.
(With BSD-style pty
s on Linux, there are matching device pairs, such as /dev/ptyp1
and /dev/ttyp1
, respectively on the master and slave side.)
On Linux, using devpts
, there is no master device file. The process on the master end uses a file descriptor, which it gets by opening ptmx
, but there’s no corresponding device node.
See the ptmx
manpage for details.
(With BSD-style pty
s on Linux, there are matching device pairs, such as /dev/ptyp1
and /dev/ttyp1
, respectively on the master and slave side.)
edited 8 hours ago
answered 8 hours ago
Stephen Kitt
164k24366445
164k24366445
add a comment |
add a comment |
That is one thing that is harder than it should be.
With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index
entry from /proc/PID/fdinfo/FD
. See this commit.
When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx
to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX
to find all processes that hold a handle to the slave pty.
With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3)
on the file descriptor.
add a comment |
That is one thing that is harder than it should be.
With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index
entry from /proc/PID/fdinfo/FD
. See this commit.
When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx
to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX
to find all processes that hold a handle to the slave pty.
With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3)
on the file descriptor.
add a comment |
That is one thing that is harder than it should be.
With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index
entry from /proc/PID/fdinfo/FD
. See this commit.
When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx
to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX
to find all processes that hold a handle to the slave pty.
With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3)
on the file descriptor.
That is one thing that is harder than it should be.
With newer kernels, the index of the slave pty paired with a master can be gathered from the tty-index
entry from /proc/PID/fdinfo/FD
. See this commit.
When that hits the stores it will be easy to do a find /proc -lname /dev/ptmx
to get a list of processes holding a handle to a master pty, get the index from each of them, and then do another find -lname /dev/pts/INDEX
to find all processes that hold a handle to the slave pty.
With older kernels, the only way you can get that is by attaching with a debugger to a process holding a master pty, and call ptsname(3)
on the file descriptor.
answered 6 hours ago
mosvy
6,1411425
6,1411425
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f492302%2fhow-can-we-find-out-the-pseudoterminal-master-and-slave-from-each-other%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
2
Possible duplicate of Are all the slaves paired with the same master?
– JdeBP
8 hours ago