|
The younger brother wrote a program on LINUX, according to the book <unix advanced environment programming>,
If the session leader does not specify O_NOCTTY, the terminal device will be opened to obtain the controlling terminal;
Conversely, if specified, the controlling terminal will not be obtained.
But the program indicates that it still doesn't work or get the control terminal, because I wrote extra
Using a subroutine to open the non-session group leader can't get the control terminal. When opening tty12,
"No job control in the Shell" is displayed, indicating that the control terminal failed to obtain,
Why is O_NOCTTY not valid for the session leader?
code show as below:
#include <sys / stat.h>
#include <unistd.h>
#include <stdio.h>
#include <sys / types.h>
#include <sys / stat.h>
#include <fcntl.h>
#include <stdlib.h>
int main ()
{
pid_t pid = fork ();
if (pid> 0)
exit (0);
if (pid <0)
printf ("first fork error\n"), exit (1);
if (setsid () <0)
printf ("sedsid () error\n"), exit (1);
umask (022);
close (0);
close (1);
close (2);
int _new = open ("/ dev / tty12", O_RDWR | O_NOCTTY);
dup2 (_new, 0); // Repoint to stdin
dup2 (_new, 1); // Repoint to stdout
dup2 (_new, 2); // Repoint to stderr
execl ("/ bin / bash", "bash", (char *) 0);
} |
|