Homework:
A collection of one or more processes, a foreground job can consist of multiple processes, and a background job can be composed of multiple processes. The shell does not really control the process but the job, the shell can only run one foreground job and any number of background jobs, which is control of the job.
Process Group:
Each process belongs to a process group, each group has a unique process group ID, and each process group has a leader process. As long as a process group exists, the process group exists, regardless of whether the leader process terminates.
Session:
A collection of one or more process groups, including a control process (the session first process), a foreground process group, and any number of background process groups.
Terminal:
with a shell process is obtained after the user logs into the system via the terminal, which becomes the control of the shell process terminal (controlling Terminal), the control terminal is the information stored in the PCB, the call fork will copy the PCB information, the terminal is also the control terminal of other processes initiated by the shell process. For each terminal, the control process associated with the control terminal is bash (session first process). Each process accesses its control terminal through a special device file,/dev/tty.
Daemon (Wizard process):
is a special process running in the background, it is independent of the control terminal (that is, not associated with the terminal), as a single session, can not be controlled before and after the console.
The use of daemons:
Linux systems start with a number of system service processes, such as inetd during the network logon process, which do not control the terminal and do not interact directly with the user. Other processes are created when a user logs on or running a program, terminates at the end of the run or when the user logs off, but the system service process is not affected by user logon logoff, and they are always running.
The key to creating a daemon is to call the SETSID function to create a new session and become the session Leader.
When the function call succeeds, the ID of the newly created session is returned (in fact, the ID of the current process), and the error returns-1.
Note that the current process does not allow the leader of the process group until this function is tuned , otherwise the function returns-1.
The result of a successful call to this function is:
1. Create a new session, the current process becomes session Leader, the ID of the current process is the session ID.
2. Create a new process group, the current process becomes the leader of the process group, and the ID of the current process is the ID of the process group.
3. If the current process originally has a control terminal, it loses the control terminal and becomes a non-control terminal in the
Ride. The so-called loss of control Terminal refers to the original control terminal is still open, can still read and write, but only a general
Open the file instead of the control terminal.
Daemon creation:
1. Call Umask to set the file mode creation Shield Word to 0
2. Make the init process the parent process of the new generation process, after calling fork () to create the child process, the parent process exits immediately, the resulting child process becomes an orphan process and is taken over by the Init process, and the resulting new process becomes in the background.
3. Call the Setsid function so that the newly created process is detached from the control terminal, creating a new process group and becoming the first process of the process. Setsid function Prototype: pid_t setsid (void);
4. Register the signal processing function, so that the SIGCHLD signal is ignored action processing
5. Fork again, terminate the parent process, keep the child process is not the first session, so that subsequent will not be associated with other terminals
6. Close the unwanted file descriptor while redirecting three standard file descriptors.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7F/D2/wKioL1cu5xvQSAJcAABcEkK4e0M229.png "style=" float: none; "title=" 1.png "alt=" Wkiol1cu5xvqsajcaabcekk4e0m229.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/D4/wKiom1cu5kGwMNMyAABDWYJwvIY050.png "style=" float: none; "title=" 2.png "alt=" Wkiom1cu5kgwmnmyaabdwyjwviy050.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/D2/wKioL1cu5xzQRSIGAABqjpn3UIc316.png "style=" float: none; "title=" 3.png "alt=" Wkiol1cu5xzqrsigaabqjpn3uic316.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7F/D2/wKioL1cu5xzR18BdAAAhFAph4Ec401.png "style=" float: none; "title=" 4.png "alt=" Wkiol1cu5xzr18bdaaahfaph4ec401.png "/>
Viewing processes in the system using the PS AXJ command
Parameter A indicates that not only the process of the current user is listed, but also all other users ' processes, the parameter x indicates that not only the process of the control terminal is listed, but also all the processes that have no control terminal, and the parameter J indicates that the information related to the job control is listed.
View the daemon: using PS AXJ | Grep-e ' My_daemon '
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/D4/wKiom1cu59uRnHQuAABDQnJApQs299.png "title=" 6.png " alt= "Wkiom1cu59urnhquaabdqnjapqs299.png"/>
Can you see the TTY for this process? , indicating that the program has no control terminal
Jobs, endpoints, daemons