How can a process (in my case session leader) get controlling terminal?
What I do in my program:
1. fork;
2. parent -> while(1) or smth. similar;
3. child -> setsid();
exec "man ps";
I beleived that i would get nothing in the output. (child is a session leader and therefore now it has no relation to old tty) But i got and don't understand why. Man ouputs. But is not interactive. When I press Ctrl-z it becomes interactive when i press 'q' it quites and returnes to my prog(parent). So the questions are:
- Please explain what happens at the beginning (why I have to press ctrl-z, read above)
- Why man does some output in that shell?
- How can man do it without any tty connected (I checked it with ps, man and pager have "?" in TTY column)
- And finally: how can a new session leader acquire a controlling terminal. Are there any wayes besides
open(/dev/tty)
?