From: deng@pertsserver.cs.uiuc.edu (Zhong Deng)
Subject: Question: How to open a control terminal?
Date: 1995/07/28 [thread overview]
Message-ID: <3vavke$9c9@vixen.cso.uiuc.edu> (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]);
}
reply other threads:[~1995-07-28 4:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox