Write directory title here
Introduction to Linux process
A Linux process is an instance of a program running in a computer. In a Linux system, each process has a unique process ID (PID), which is used to identify the process. (pid) Process ID.
Linux processes are managed and scheduled by the kernel, and they can be in different states, such as running, blocked, ready, etc. The process interacts with the kernel through the system call interface (API) to complete various operations, such as file reading and writing, network communication, resource allocation, and so on. Moreover, each process has its own address space, so that they are isolated from each other, which can better protect the stability and security of the system.
In the Linux system, the user can view the currently running processes through the command line interface or the graphical interface, and perform operations on them, such as terminating a process, adjusting the priority of the process, etc., these functions use the management tools provided by the Linux operating system Completed.
A process also has its own memory space, including code, data, and stack. Through these memory spaces, a process can store state and data during its lifetime and communicate with other processes.
In summary, a Linux process refers to an independently running unit of activity on the Linux operating system that occupies CPU time and allocates other computer resources to efficiently perform work and coordinate the execution of applications.
Every process may exist in two ways - foreground and background.
The so-called foreground process refers to the process that the user can currently operate on the screen.
The background process is actually operating, but because the process cannot be seen on the screen, it is usually executed in the background.
Generally, system services exist in the form of background processes, and they will be resident in the system until the system is shut down.
Display the processes executed by the system
ps command
It is used to check which ones are being executed in the current system and their execution status. No parameters can be added
ps -a: Display all process information of the current terminal
ps -u: Display process information in user format
ps -x: Display the parameters of background process running
Then the ps process display information options:
field | illustrate |
---|---|
PID | process id |
TTY | terminal number |
TIME | cpu time consumed by this process |
CMD | The command or process name being executed |
USER | process execution user |
MEN | Percentage of physical memory occupied |
VSZ | The size of virtual memory occupied (in kb) |
RSS | Physical memory size occupied (in kb) |
STAT | Process running status (s stands for sleep) (r stands for running) (D short-term waiting) (Z zombie process) (T is tracked or stopped) |
START | execution start time |
CMMAND | Process name, the command to execute the process |
ps -aux|grep ***
Filter services through pipeline commands
ps -ef displays all current processes in full format
-e show all processes
-f full format
terminate process
If a process needs to be stopped in the middle of its execution, or a large amount of system resources have been consumed, you can consider stopping the program at this time, and you can use kill to complete this task.
Basic syntax:
kill [option] process number (kill/process by process number)
killall process name (child process will also be removed)
kill -9 force the process to end
View process tree pstree
Basic syntax:
pstree [option] can view process information more intuitively
pstree -p displays the PID of the process
pstree -u displays the user who owns the process
Linux process role
1. Executing applications
The main function of a Linux process is to execute applications. When the user enters a command in the terminal, the operating system will start a new process to execute the application corresponding to the command. For example, when the user enters the "ls" command, the operating system will start a new process to execute the "ls" application, which will list all the files and folders in the current directory.
2. Provide system services
Linux processes can also provide system services. For example, network service processes (such as HTTP, FTP, SSH, etc.) can run in the background to provide services for other computers. These service processes can be automatically started when the operating system is started, and run all the time when the operating system is running.
3. Manage system resources
Linux processes can also manage system resources. Each process in an operating system can use a certain amount of system resources, such as CPU, memory, disk space, and so on. Processes can request and release these resources so that they can function better. For example, a process can request more slices of CPU time so that it can run faster.
4. Communicate with other processes
Linux processes can also communicate with other processes. Processes can communicate through mechanisms such as pipes, sockets, and shared memory. These communication mechanisms allow processes to share data so that they can work better together. For example, one process can send a message to another process so that they can work together to complete a certain task.
In addition, if you have a need to buy books, you are welcome to consider Tsinghua News Agency, and you can directly buy the best books at the lowest price!
Details https://pro.m.jd.com/mall/active/3Rho97HkMaGFycLzAWfFdvZdyvRn/index.html
On 618, the Tsinghua News Agency IT BOOK activity started! The activity time is from June 7th to June 18th, 2023. Tsinghua
News will select a
variety The field of IT development is suitable for readers of different levels. 50% off sitewide, even more discounts by scanning the QR code to receive coupons! Come to Jingdong and click on the link IT BOOK
(or scan the QR code of Jingdong) to view the details!