Linux process management related content

  
3. Command parameters: -l signal, if the number parameter of the signal is not added, use the “-l” parameter to list all signal names -a When processing the current process, the correspondence between the command name and the process number is not limited -p Specify the kill command to print only the process ID of the relevant process without sending any signal -s Specify the send signal -u Specify the user Note: 1. The kill command can be with or without the signal number option. If there is no signal number, the kill command will issue a termination signal (15), which can be captured by the process so that the process can clean up and free resources before exiting. You can also use kill to send a specific signal to the process. For example: kill -2 123 The effect is equivalent to pressing Ctrl+C while running the process with PID 123 in the foreground. However, normal users can only use the kill command without the signal parameter or use the -9 signal at most. 2, kill can have the process ID number as a parameter. When using kill to signal to these processes, they must be the masters of those processes. If you try to undo a process that does not have permission to revoke or revoke a process that does not exist, you will get an error message. 3. You can signal or terminate multiple processes. 4. When the kill successfully sends the signal, the shell will display the termination information of the process on the screen. Sometimes this information is not displayed immediately, it will only be displayed when the Enter key is pressed to make the shell's command prompt appear again. 5, should pay attention to the signal to force the process to terminate, which often brings some side effects, such as data loss or the terminal can not be restored to normal state. Care must be taken when sending a signal, and the kill signal (9) is used only when it is absolutely necessary, because the process cannot capture it first. To undo all background jobs, type kill 0. Because some commands running in the background will start multiple processes, it is cumbersome to track and find the PID of all the processes to be killed. At this point, using kill 0 to terminate all processes started by the current shell is an effective method. Signal description: Only the ninth signal (SIGKILL) can terminate the process unconditionally, and other signal processes have the right to ignore. The following are commonly used signals: HUP 1 terminal disconnection INT 2 interrupt (same as Ctrl + C) QUIT 3 exit (same as Ctrl + \\) TERM 15 terminate KILL 9 forced termination CONT 18 continues (in contrast to STOP, fg/bg command) STOP 19 Pause (same as Ctrl + Z) Parent and child processes Each Linux process contains two process IDs: the current process ID (pid) and the parent process ID (ppid). You can temporarily assume that all processes have a parent process. Most commands run by the user use the shell as the parent process. Use the ps -f command to view the current process ID and the parent process ID. Zombie Processes and Orphan Processes Normally, when a child process is terminated, the parent process is signaled by SIGCHLD, which can do some cleanup or restart a new process. But in some cases, the parent process will be terminated before the child process, then these child processes have no "father", known as the orphan process. The init process becomes the parent of all orphan processes. The inpid pid is 1, which is the first process of the Linux system and the parent of all processes. If a process is terminated, but the process can still be viewed using the ps command, and the status is Z, then this is a zombie process. Although the zombie process is terminated, it still exists in the process list. Generally, zombie processes are hard to kill. You can kill their parent process first, let them become orphan processes, and the init process will automatically clean up the zombie process. Resident Process The resident process is generally a system-level process that runs in the background with root privileges and can handle requests from other processes. The resident process has no terminal and cannot access the /dev/tty file. If you use ps -ef to view the process, the tty column displays a question mark (?). More specifically, the resident process usually runs in the background, waiting for a specified event to occur. For example, the print process is a resident process that waits for the user to enter print-related commands and process them. The top command The top command is a useful tool for dynamically displaying running processes and sorting processes according to specified criteria, similar to Windows Task Manager. The top command can display a lot of information about the process, including physical memory, virtual memory, CPU usage, average load, and busy processes. For example: $top Tasks and Processes Tasks are the most abstract and are a general term referring to an activity done by software. A task can be either a process or multiple processes. In short, it refers to a series of operations that work together to achieve a certain purpose. For example, reading data and putting it into memory. This task can be implemented by one process or by multiple processes. Each task has a task number that is represented by a number. Processes are often defined as the execution of a program. Think of a process as a stand-alone program with its complete data space and code space in memory. The data and variables owned by a process belong to itself. The jobs command can be used to view tasks that are running on the system, including tasks that run in the background. This command displays the task number and its corresponding process ID. A task can correspond to one or more process numbers. The -l option of the jobs command can view the process IDs contained in the current task: $jobs -l [1] + 1903 running ls ch*.doc & $ where the first column represents the task number and the second column represents the process corresponding to the task ID, the third column indicates the running status of the task, and the fourth column indicates the command to start the task. Switching between foreground and background tasks The fg command can bring the background task to the foreground. The syntax is: $fg %jobnumber jobnumber is the serial number of the background task obtained through the jobs command. Note that it is not pid. If there is only one task in the background, you can not specify jobnumber. The bg command can transfer the suspended tasks in the background to the foreground to continue running. The syntax is:
Copyright © Windows knowledge All Rights Reserved