Bird Brother Linux Private Kitchen Chapter 17 Program Management and SELinux Exploration

Bird Brother Linux Private Kitchen Chapter 17 Program Management and SELinux Exploration

17.1 What is a process

In the Linux system: when any event is triggered, the system will define it as a process and give the process an ID called PID. At the same time, according to the relationship between the user who triggered the process and related attributes, the PID is given a set of valid Permission settings. From then on, the operations that this PID can perform on the system are related to the permissions of this PID.

17.1.1 Process and Procedure

  • Program: usually a binary program placed on a storage medium (such as hard disk, CD, floppy disk, tape, etc.) in the form of a physical file
  • Process: After the program is triggered, the permissions and attributes of the executor, the program code and required data of the program, etc. will be loaded into the memory. The operating system will give the unit in this memory an identifier (PID). In other words, a process is a running program.

17.2 Job control

This job control (job control) is used in the bash environment, that is to say: after we log in to the system and get the bash shell, we can perform behavior management of multiple jobs at the same time under a single terminal. For example, after logging in to bash, we want to copy files, search for data, compile, and write vi programs. Of course, we can log in to the terminal environment of the 6 command line interfaces repeatedly, but it can also be implemented in a bash, which is to use job control.

17.2.1 What is work management

To perform bash job control, the restrictions that must be noted are:

  • The process triggered by these tasks must come from a child process of your shell (only manage your own bash)
  • Foreground: This environment where you can control and execute commands is called foreground work
  • Background: a job that can run by itself, you can't use [Ctrl] + C to terminate it, you can use bg/fg to call the job
  • Processes executing in the background cannot wait for terminal/shell input (input)

17.2.2 Job control management

The actual job control command

  • Directly throw the command to the & executed in the background: the space + & at the end of the command can execute the command in the background. However, all the output of this command will still be printed on the current interface at this time, and the influence of background work on the foreground interface can be excluded by redirection.
  • Throw the current work to the background and pause: [Ctrl] + Z
  • View the current background job status: jobs. -l displays job PID; -r only displays jobs running in the background; -s only displays jobs that are paused in the background.
  • Bring the background work to the foreground to process: fg. fg %[job number] Restore the background work of a certain job number to the foreground. However, if the job number is not specified, the last job that was placed in the background will be restored. View background jobs through jobs, display + indicates the most recently placed job, and display-indicates the next most recently placed job.
  • Let the status of work in the background become running: bg. Also use bg %[job number] to specify the work to be performed in the background.
  • Work in the management background: kill. You can check all supported signals by kill -l. The command format is kill -[signal] %[job number], where -1 means re-read the configuration file of the parameters; -2 executes Ctrl + C operation; -9 forcefully deletes a job immediately; -15 (-SIGTERM) The normal procedure is to terminate a job. The default operation object of kill is the process, so you can omit% and use PID to operate directly.

17.2.3 Offline management issues

It should be noted that the background we mentioned in the work management refers to a situation in which the [Ctrl] + C interruption can be avoided in the terminal mode, and is not placed in the background of the system. Therefore, the background of work management is still related to the terminal. In this case, if you connect to your Linux host by remote connection, and put the work in the background in the way of &, if you go offline before the work is finished, the work will not be Continued execution.

If you need to execute in the background of the system, you can use the at command or nohup to handle it.

nohup [command and parameter] (&) works in the foreground (background) of the terminal. But nohup does not support bash built-in commands, so your commands must be external commands. At the same time, nohup redirects the output of this command to the nohup.out file in the current path by default.

17.3 Process Management

Practical problems that process management can solve:

  • When the entire system resources are about to be used up, is it possible to find the process that consumes the most system, and then delete the process to restore the system to normal?
  • If a program is not well written and a problematic process is in the memory, how do you find it and delete it?
  • At the same time, there are five or six tasks running in your system, but one of the tasks is the most important. How to make that important task be executed first?

17.3.1 View of the process

ps: Select the process running status at a certain point in time. ps -l check your own bash program; ps aux check all the programs running on the system.

ps -l result description:

  • F: Represents the process flags (process flags), indicating the permissions of this process. 4 means that the permission of this process is root, 1 means that this process can only be copied (fork) but cannot be actually executed (exec).
  • S: Represents the status of this process (STAT). R (Running) the process is running; S (Sleep) the process is currently in the sleep state (idle), but can be awakened (signal); D can not be awakened in the sleep state, usually the process may be waiting for I/O Situation; T stopped state; Z (Zombie) zombie state, the process has been terminated but cannot be deleted out of memory.
  • UID/PID/PPID
  • C: represents the CPU usage, the unit is percentage
  • PRI/NI: The abbreviation of Priority/Nice, which represents the priority of the process executed by the CPU, the smaller the value, the faster the process is executed by the CPU
  • ADDR/SZ/WCHAN: They are all related to memory. ADDR is a kernel function, indicating which part of the memory the process is in. If it is a running process, it will generally display -. SZ represents how much memory is used by this process. WCHAN indicates whether the current process is running or not. Similarly, if it is -, it means it is running.
  • TTY: the terminal location of the login person, if it is remote login, use the dynamic terminal interface (pts/n)
  • TIME: CPU time used, note that this program actually spends CPU running time, not system time
  • CMD: is the abbreviation of command, what is the command that caused this program to trigger the process

ps aux result description:

  • USER: which user account the process belongs to
  • %CPU: The percentage of CPU resources used by the process
  • %MEM: The percentage of physical memory occupied by the process
  • VSZ: The amount of virtual memory used by the process (KB)
  • RSS: The fixed amount of memory occupied by the process (KB)
  • START: the time when the process was triggered to start
  • COMMAND: The actual command of the process

top: View the changes of the process dynamically.

pstree: describe the relationship of the process in the form of a tree

 

Guess you like

Origin blog.csdn.net/a40850273/article/details/104169257