Terminal, job control and daemon process

Source: Internet
Author: User
Tags terminates

  1. Process groups, jobs, sessions


    1.1 Process Group

    A. Each process belongs to a process group in addition to a process ID. A process group is a collection of one or more processes. Typically, they are associated with the same job and can receive various signals from the same terminal.

    B. Each process group has a process group ID and a leader process, and the ID of the leader process is the process group ID.

    C. Leader process you can create a process group.

    D. The process group exists, regardless of whether the leader process terminates, as long as a process group has another process in existence.


    1.2 Jobs (Job)

    A. The shell is not a process but a job or a process group that controls the front and back tables.

    B. The shell can run a foreground job and any number of background jobs, which is called job control.

    C. A foreground job can consist of multiple processes, and a background can be composed of multiple processes.

    D. Once the job is finished, the shell mentions itself to the foreground, and if the original foreground process still exists (if the child process has not yet terminated), it automatically becomes the background process group


    1.3 Sessions (session)

    A. A collection of one or more process groups.

    B. A session can have a control terminal.

    C. Establishing a session that connects to the control terminal the first process is called the control process.

    D. Several process groups in a session can be divided into one foreground process group and one or more background process groups. Therefore, a session should include the control process (session first process), a foreground process group, and any background process group.


    1.4 The difference between a job and a process group: If a process in the job creates a child process again, the child process does not belong to the job.


  2. Terminal

    The modules that handle terminal devices in the kernel include hardware drivers and wiring procedures (line discipline).


    2.1 Hardware Drivers

    The hardware driver is responsible for reading and writing actual hardware devices, such as reading from the keyboard and outputting characters to the display.


    2.2 Line procedures like a filter, for some special characters is not to let it pass directly, but do special processing, such as pressing ctrl-z on the keyboard, the corresponding characters will not be read by the user program, but is intercepted by the line procedures, interpreted as SIGTSTP signal to the foreground process, Usually causes the process to stop. Which characters should be filtered by the line procedure and what special handling to make is configurable.


    2.3 Terminal devices have input and output queue buffers, as shown in.

    650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/DF/wKioL1cwj0eCSF1LAABcoyW0UY4936.png "title=" capture. PNG "alt=" Wkiol1cwj0ecsf1laabcoyw0uy4936.png "/>

    Parsing: Taking the input queue as an example, when the characters entered from the keyboard are filtered through the line procedure, the user reads the data first in first out. Entering data into the input queue when the input queue is full can result in data loss and a ringing alert. At this point, the terminal can be configured by the Echo mode, in this mode, the terminal can put each character to the output queue can also be given to the user program. That is, characters can be read not only by the program but also by the screen.


  3. Terminal logon Process

    1, when the system starts, the INIT process determines which terminals need to be opened according to the profile/etc/inittab. For example, there is a line in the configuration file: 1:2345:respawn:/sbin/getty 9600 tty1

    Similar to/etc/passwd,

    A. Each field is separated by a: number. The first 1 is the ID of this line of configuration, usually with the suffix of the TTY, the row ID of the configuration tty2 should be 2.

    B. The second field 2345 indicates that the RunLevel 2~5 is performing this configuration.

    C. Last field/sbin/getty 9600 tty1 is the init process to fork/exec command, open terminal/dev/tty1, baud rate is 9600 (baud rate only for the serial port and modem terminal meaningful), and then prompts the user to enter the account. The Respawn field in the middle indicates that the INIT process monitors the running state of the Getty process, and once the process terminates, Init fork/exec the command again, so we will again prompt for the account after exiting the login from the terminal.

    D. Some new Linux distributions do not have to/etc/inittab this configuration file, such as Ubuntu with the/ETC/EVENT.D directory

    Configuration file to configure Init.


    2, Getty According to the command line parameters open Terminal Equipment as its control terminal, the file descriptor 0, 1, 2 point to the control terminal, and then prompt the user to enter the account. After the user enters the account, Getty's task is completed, and it executes the login program:

    Execle ("/bin/login", "Login", "-P", username, NULL, envp);


    3, the login program prompts the user to enter the password (enter the password during the closing of the Terminal Echo), and then verify the correctness of the account password. If the password is incorrect and the login process terminates, Init will re-fork/exec a Getty process. If the password is correct, the login program sets some environment variables, sets the current working directory as the user's home directory, and executes the shell:

    Execl ("/bin/bash", "-bash", NULL);

    Note The program name of the argv[0] parameter is preceded by one-so that bash knows that it is launching as a login shell and executes the startup script of the login shell. Starting from Getty exec to login, and then exec to bash, is actually the same process, so the control terminal has not changed, the file descriptor 0, 1, 2 also still point to the control terminal. Because fork replicates the PCB information, so do other processes that are started by the shell.


  4. Job control: A foreground job can consist of multiple processes, a background job can also consist of multiple processes, and the shell can run one foreground job and any number of background jobs at the same time.

    A. The shell is not a process but a job or a process group that controls the front and back tables.

    B. When a user enters a special control key (for example, Ctrl-c) in the control terminal, the kernel sends a corresponding signal (for example, SIGINT) to all processes in the foreground process group.

  5. Daemon (Daemon)

    5.1 Definitions

    A. System service processes are not affected by user logon logoff, they are always running. This process is called the daemon process.

    B. Daemons, also known as daemon processes, are a special process that runs in the background. It is independent of the control terminal and periodically performs some sort of task or waits to handle certain occurrences. Daemons are a very useful process.

    C. Most Linux servers are implemented with daemon processes. For example, Internet Servers Inetd,web server HTTP, and so on. The daemon completes many system tasks. For example, the job planning process crond and so on.


    5.2

    Use the PSAXJ command to view the processes in the system.

    A. Parameter a indicates that not only the process of the current user is listed, but also the processes of all other users;

    B. The parameter x indicates not only the process of controlling the terminal, but also all the processes without control terminal;

    C. The parameter J indicates that the information related to the job control is listed.

    5.3 All Tpgid A column is written-1 is the process of no control terminal, that is, the daemon process.

This article is from the "sunshine225" blog, make sure to keep this source http://10707460.blog.51cto.com/10697460/1771733

Terminal, job control and daemon process

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.