The 17th chapter, the procedure management and the SELinux research

Source: Internet
Author: User
Tags touch command

---restore content starts---

What is a program (process)

Under Linux all the commands and actions you can do are related to permissions, and the system depends on the uid/gid and the attributes of the file to determine your permissions! In the Linux system: " trigger any event, the system will define him as a program, and give the program an ID, called PID, and according to inspire the user of this program and related attribute relationship, give this PID a set of effective permissions configuration." "From then on, this PID can be carried on the system above the action, and this PID permissions related!"

Processes and Procedures (Process & program)

"Run a program or command" can trigger an event and get a pid! The system only knows binary file, so the system needs to start a binary file, the binary file is the program!

"When you run this program with a different user identity, the system does not give you the same permissions!" "For example, we can use touch to create an empty file, and when Root runs the touch command, he gets the Uid/gid = 0/0 permission, and when Dmtsai (uid/gid=501/501) runs the touch, his permissions are Root is different!


Figure 1.1.1, the program is loaded into the program and related data

As shown, the program is usually placed in the physical disk, and then through the user's operation to trigger. Triggered and then loaded into memory as an individual, that is the process. For the operating system to manage the program, so the process has to give the user the permissions/attributes and other parameters, and include the program required command code and data or file data, and finally give a PID. The system is through this PID to determine whether the process has permission to work!


Figure 1.1.2, program-to-process differences

In other words, when we log in and run bash, the system has given us a PID, this PID is based on the Uid/gid (/etc/passwd) to the top of the figure 1.1.2 Diagram 1.1.1 To do the illustration, we know/bin/bash is a program, when Dmtsai landed, he obtained a PID number of 2234 process, the process of User/group is Dmtsai, and when the process to do other jobs, such as the above mentioned Touch This command, then by this process derived from other processes in the general state, will also continue to follow the process of the relevant permissions!

Let's make a summary of the procedure and process:

    • Programs: Usually binary program, placed in the storage media (such as hard disk, CD-ROM, floppy disk, tape, etc.), the form of the entity file exists;

    • Process: After the program is triggered, the user's permissions and properties, program code and required data will be loaded in memory, the operating system and give the memory Unit a recognition code (PID), it can be said that the process is a running program.


    • Child process and Parent process:

When we log into the system, we get a bash shell, and then we use this bash to run another command, such as/USR/BIN/PASSWD or touch and so on, those other running commands will be triggered to become PID, the later Run command to produce PID is a "sub-process", and in our original bash environment, called the "Parent program"!


Diagram 1.1.3, process phase relationship

Processes are relevant to each other! In the above illustration, after running two bash in a row, the second bash's parent process is the previous bash. Because each process has a PID, how does the parent program of a process judge? It can be judged by the Parent PID (PPID). In addition, from the export content of Chapter 11 We also discussed the inheritance of environmental variables, the child process can get the parent process environment variables! Let's do the exercises below to understand what a child process/parent process is.

Example: In the current bash environment, one more bash, and the "ps-l" command to see the output of the relevant process information. A: Run bash directly, will go into the child process environment, and then enter Ps-l after, appear: F S UID PID PPID C PRI NI ADDR SZ wchan TTY time CMD4S0  8074  8072  2   the   0-1287 waitpts/1    xx:xx:xxBash0S0  8102  8074  4   the   0-1287 waitpts/1    xx:xx:xxBash4R0  8118  8102  0   +   0-1101-pts/1    xx:xx:xxPS have you see that PID and PPID? The first bash PID and the second bash's PPID are8074Ah, because the second bash comes from the first one! In addition, each host of the program start state is different, so on your system see the PID and I here is a certain difference! That's normal! Detailed PS command we will introduce later in this chapter, here you just know ps-l can check the relevant program information.

Many friends often find: "Gee!" Clearly I will have the problem of the program closed, how can he be automatically generated after a while? And the new program's PID is not the same as the original, what is the matter? "Do not doubt, if not the impact of crontab work scheduling, there must be a parent program exists, so you kill the subroutine, the parent program will actively regenerate one!" So what? This is the so-called: "The thief first to seize the King", find out the Father program, and then delete it is right!

    • Fork and Exec: Process call process

In fact, the relationship between the child process and the parent process is quite complex, and the biggest complication is the call between the process and each other. The process of calling on Linux is usually called the fork-and-exec process (Note 1)! The program will produce an identical child process by copying (fork) in the parent process, and then the child process that is copied will then run the actual program in an exec manner, eventually becoming the existence of a child process. The whole process is a bit like the bottom picture:


Figure 1.1.4, where the program uses fork and exec calls

(1) The system first copied a fork to the same cache process as the parent process, the only difference between this process and the parent process is the PID is different! But this cache process will also have a PPID parameter, PPID as described earlier, is the parent process identification code! Then (2) The cache process starts to exec load the actual program to run, in the above diagram, the new process name is QQQ, the final subroutine code will become QQQ! You know that!

    • System or NETWORK Service: A program that resides in memory

If we have learned some of the command data, in fact, our orders are very simple, including using LS display files Ah, with touch to create files Ah, RM/MKDIR/CP/MV and other commands to manage files Ah, chmod/chown/passwd and so on the command to manage permissions and so on , however, these commands end when they run out. In other words, the PID generated after the command is triggered will soon be terminated! Is there a program that's been running? Yes, of course! And many of them!

As a simple example, we know that the system scans the/etc/crontab and related configuration files every minute to schedule the work. So who's responsible for that job schedule? Of course not Brother Bird! Oh! is Crond this program to manage, we will he started in the background has been continuously running, set a sentence before the DOS era often said, that is "resident in memory Process"!

The processes that reside in memory are usually responsible for the functions provided by some systems to serve the user's tasks, so these resident procedures are referred to as: Services (daemon). The service of the system is very much, but it is mainly divided into the services needed by the system itself, such as the Crond and ATD, and the syslog and so on. Some are also responsible for network connection services, such as Apache, named, Postfix, vsftpd ... Wait a minute. These network services are interesting places where, after these processes are run, he initiates a port that can be responsible for network monitoring to provide the connection requirements of the external client (client).

Multi-person and multi-work environment for Linux

We now know, in fact, under the Linux run a command, the system will be related to the permissions, properties, code and data, such as loading memory, and give the unit a Program identification code (PID), and finally the command can be carried out by the task of the PID is related to the permissions. According to this note, we can simply understand why Linux is so many users, but everyone can have their own environment! ^_^! Let's talk about the features of the Linux multi-person and multi-work environment:

    • Multi-person Environment:

The best part of Linux is his multi-worker environment! So what is "multi-person and multi-worker"? The Linux system has a number of different accounts, each account has its own special permissions, only one person has the supremacy of power, that is, root (System administrator). Except for Root, others must be subject to some restrictions! And everyone's environment configuration that goes into Linux can be configured with everyone's preference (remember the ~/.BASHRC we mentioned in the 11th chapter of BASH?). That's right! That's the light! )! Now you know why? Because each person landed after the shell PID has different!

    • Multi-ICBC for:

We talked about CPU speed in the 0th chapter, and the current CPU speed can be up to several GHz. This means that the CPU can run more than 109 commands per second. Our Linux allows the CPU to switch between the various jobs, that is, each job only takes up a few commands of the CPU, so the CPU can switch between the various programs every second! The CPU can run so many commands in a second.

CPU switching programs work, and these work into the CPU to run the scheduling (CPU scheduling, non-crontab scheduling) will affect the overall performance of the system! The current multi-switch behavior used by Linux is a great mechanism for almost all of the performance of the PC to be squeezed out! Because the performance is very good, so when many people at the same time landing system, in fact, will feel the entire host as if you exist in general! This is a multi-worker environment! (Note 2)

    • Seven basic terminal windows for multiple landing environments:

In Linux, the default provides six text interface landing Windows, as well as a graphical interface, you can use [ALT]+[F1] ... [F7] To switch between the different terminal interface, and each terminal interface of the lander can also be different people! It's gorgeous! This thing can be very useful! Especially when a program dies!

In fact, this is a multi-work environment generated by a situation! Our Linux default will start the six Terminal Landing Environment program, so we will have six terminal interface. You can also reduce AH! is to reduce the startup of the terminal program is good. Detailed data can first consult/etc/inittab this file, in the future we start the management process (20th chapter) will be carefully introduced!

    • Special Program Management Behavior:

Old bird brother Stupid, always think that using Windows 98 is OK! Later, because of the work of the relationship, need to use the UNIX system, I want to say that I just in front of the work machine, not to run to the UNIX workstation in front of it! So just use Windows to work with my Unix workstation! Good to die, I a program to run down to 2-3 days, alas ~ often to the first 2.5 days, Windows 98 will give him to hang points! He was really scared to death.

Later because of the new computer, with a random version of Windows 2000, Oh, this thing is really good (refers to single person), in the crash, he can only the wrong program kicked off, and not interfere with other procedures, hehe! From then on, you don't have to worry about the crash! However, 2000 is not good enough, because sometimes it will die!

So does Linux have this problem? To be honest, Linux can almost say that it will never crash! Because he can kill a trapped program at any time and then rerun the program without restarting! That's cool! So if I am in the Linux under the text interface Landing, in the screen display error message after hanging up ~ Move can not move, how is good!? This time the default of seven Windows to help! You can press [ALT]+[F1] at will. [F7] To switch to the other terminal interface, and then to Ps-aux to find out just the wrong program, and then give him kill, Haha, back to just the terminal interface! Yes, great! Return to normal again!

Why is it possible to do so? Didn't we just mention it? Each program may be independent, or may have dependencies, as long as the independent program, delete the problem of the program, of course, he can be removed by the system! ^_^

    • Job Management in bash environments (Job control)

We mentioned in the previous section the so-called "parent program, subroutine" relationship, then after we landed bash, we got a PID called Bash, and the other commands running under this environment are almost all called subroutines. So, under this single bash, can I do multiple jobs? Of course you can! You can do it "at the same time." For example, I can do this:

[email protected] ~]# CP file1 File2 &

In this sequence of commands, focusing on that & function, he said to copy file1 this file as File2, and put it in the background to run, that is, after running this command, in this one terminal interface can still do other work! And when this command (CP file1 File2) is finished, the system will display the completed message in your terminal interface! Very convenient!

    • The system resource allocation problem of multi-person and multi-work is considered:

Many people and many workers do have a lot of benefits, but in fact there are management problems, because users are more and more, will lead to your management of the trouble! In addition, due to the user of the day, when the user reached a certain number of people, usually your machine will need to upgrade, because the CPU operation and the size of the RAM may not be used!

For example, bird Brother's previous site management is a bit bad, because the use of a very complex number of statistical procedures, the program will continue to fetch data from the MySQL database, but because of the large traffic, resulting in MySQL is very busy. In this case, when Brother Bird wants to log in to write Web data, or to use the resources of the discussion area, wow! It's slow! It's "Turtle speed"! Later finally, the program stopped the use of a small program to write their own to replace, hehe! In this way, the CPU load (loading) down the whole down ~ use more smoothly! ^_^

The 17th chapter, the procedure management and the SELinux research

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.