* Question: How to open a control terminal?
@ 1995-07-28 4:00 Zhong Deng
0 siblings, 0 replies; only message in thread
From: Zhong Deng @ 1995-07-28 4:00 UTC (permalink / raw)
How does one open a control terminal for a process? I tried the following
code, as sugguesed by man page tty(7). It works when the calling process
is not process group leader, but it fails when it is.
Thank you for your help.
#include <sys/ioctl.h>
#include <fcntl.h>
main(int argc, char **argv)
{
int fd;
if (argc != 2) {
printf("Usage: %s port\n", argv[0]);
exit(1);
}
if (setsid() < 0) {
fd = open("/dev/tty", O_RDWR);
if (fd < 0) {
perror("open /dev/tty");
exit(1);
}
if (ioctl(fd, TIOCNOTTY, 0) < 0) {
perror("ioctl TIOCNOTTY");
exit(1);
}
close(fd);
}
fd = open(argv[1], O_RDWR);
if (fd < 0) {
perror("open ctty");
exit(1);
}
if (ioctl(fd, TIOCSCTTY, 0) < 0) {
perror("ioctl TIOCSCTTY");
exit(1);
}
printf("Control terminal %s opened\n", argv[1]);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1995-07-28 4:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-07-28 4:00 Question: How to open a control terminal? Zhong Deng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox