From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,7183f3c1d02ecd1f,start X-Google-Attributes: gidfee84,public From: deng@pertsserver.cs.uiuc.edu (Zhong Deng) Subject: Question: How to open a control terminal? Date: 1995/07/28 Message-ID: <3vavke$9c9@vixen.cso.uiuc.edu>#1/1 X-Deja-AN: 107033285 distribution: world organization: University of Illinois, Dept of Comp Sci, Urbana, IL newsgroups: comp.unix.osf.osf1 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 #include 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]); }