| |

VerySource

 Forgot password?
 Register
Search
View: 1834|Reply: 2

O_NOCTTY Forbidden to obtain terminal control Invalid?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Taiwan

Post time: 2020-1-19 15:00:01
| Show all posts |Read mode
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);
    
}
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-30 13:30:01
| Show all posts
bash will retrieve the session terminal
Reply

Use magic Report

0

Threads

1

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-7-7 09:33:08
| Show all posts
: @: lol solved?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list