"Apue" Chapter9 Process relationships

Source: Internet
Author: User

This chapter is a bit confusing, probably because of the few examples, and again, this chapter is a foreshadowing chapter.

9.2 Terminal Logins

What do you mean termnial? I feel that the terminal in the book is more likely to be a physical device (keyboard, modem)

These terminals are stored in the/etc/ttys, and a line represents the information of a terminal.

Limited to basic knowledge, the above may be wrong to understand, but for terminal logins one thing is certain: the computer beforehand know how many terminals can logins.

The BSD Terminal logins is the focus of the main process, the following process is as follows:

    Init (Process ID 1)

?? Fork once per terminal;creates empty environment

    Init

?? Each child execs Getty

    Getty

?? opens terminal device; Real user name; initial environment set;

    Login

??

?? File Descriptor 0 1 2

    Terminal device driver

??

?? hard-wired Connection

    User at a terminal

In the above process, you can see the role of Fork exec in Chapter 8.

(1) See what happened to Getty (including Getty) First

  Environment: Init to Getty or an empty environment;getty himself create a environment and then passed to login, This time environment has included terminal information (such as term).

  Open Terminal device: Turn on terminal device, set file descriptor 0 1 2 (input, output, error)

  Read user name: output similar to "login:" Waiting for users to enter

You can use the following content to understand Getty:

  execle ("/bin/login", "Login", "-P", username, (char*) 0, envp);

Finally Getty called the login program

(2) See what login has done

A. Get the password and verify the password.

B. Convert to this user's home path

C. Convert the ownship of terminal device to the user

D. Setting GroupID

E....

9.3 Network Logins

Unlike terminal logins, computers are unaware of how many, and those, who, want the network logins.

Therefore, there is no terminal configuration file that can be read like a/etc/ttys line. What do we do? This is going to be handled in a similar service way.

In order to be able to eventually unify the processing of terminal and network in the Logins,unix system there is a pseudo terminal wit, can be translated into virtual terminal.

Why do you have a virtual terminal?

I think there are two reasons:

1) As an end user, personal habits, remote network operation and terminal operation do not want to be different

2) as a UNIX system, since the terminal logins program has been developed, naturally hope that the network logins program can be reused terminal logins of the processing program. Because they are different in the way they log in, the content is similar once they interact with the system.

Therefore, pseudo terminal appeared, completed the above demands. Even from the network logins, as long as login is completed, and terminal operation is not different.

The following is just a matter of how to generate pseudo terminal, the process is as follows.

                        Init process ID 1

TCP connection request from TELNET client→?? Executes the shell SCRIPT/ETC/RC

                        inetd

?? Fork (when connection request arrives from TELNET client)

                        inetd

??

                        telnetd

??

                        Pseudo Terminal device

?? Fork

Parent Process:handle the communication across the network connection

Child Process:does A exec of the login program

Parent & Child connected through the pseudo terminal

                        Child process

??

??

Login Shell

The above process is:

During the start-up phase of the system, Init executes a/etc/rc shell script, which is designed to start inetd daemons.

Then inetd Daemons waited until a request from the Telnet client forked out a little brother inetd to handle the request.

The way the inetd brother handles the request is to execute Telnet server, or telnetd.

The telnetd then opens a pseudo terminal device and divides it in a fork:

Parent process: Responsible for the management of network connection

Child process: Responsible for executing login-related things

The parent and child are associated by pseudo terminal.

9.4 Process Group

A bunch of process groups, guessing that there is a process group in order to facilitate collective operation of some type of process. Not elaborate.

9.5 Sessions

Multiple process groups form the session.

9.8 Job Control

In this part of the book there is an example, from the result: a shell without job control, a terminal can only produce a pgid; a shell with job control, a terminal can produce several pgid.

9.10 Orphaned Process Groups

Because of the lack of knowledge behind signal, just look at 9.12 of this code.

The code is not complex and is not documented here in detail.

The only place that makes me wonder.

...
Signal (SIGHUP, sig_hup); Kill (Getpid (), SIGTSTP);
...

There are two lines in the source code that are executed in the child process after the fork.

First put the signal no matter, this kill is more difficult to understand: kill, why the child process after the statement can also be executed?

Man 2 Kill First: "Kill-send signal to a process". That's what kill does is send a signal

So what do you mean by looking at the signal sent SIGTSTP?

There is a passage in the book: "Unfortunately, the term stop has different meanings ... Therefore, the terminal driver calls the character that generates the interactive stop signal the suspend character, not t He stop character ".

Can be understood as: Stop here is not to say directly to get lost, but first let the process wait for the meaning.

Come back and see signal.

The source code deliberately lost the parent process, leaving the child process, which resulted in the orphaned process group situation. As required by the system, for all remaining processes in the orphaned process group, a hang-up signal (SIGHUP) is sent, followed by a sigcont signal. Signal this statement is to enable the child process to receive the sighup signal, and continue to execute.

Through this thing, this kill and his original meaning is still much worse, still need to pay more attention to some.

  

     

  

  

  

"Apue" Chapter9 Process relationships

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.