What does process mean in linux?

青灯夜游
Release: 2021-11-30 16:19:14
Original
4636 people have browsed it

A process is an instance of a program running in Linux and is the basic unit for managing transactions; a process has its own independent processing environment and system resources. The status of a process changes, including process creation, scheduling, and death.

What does process mean in linux?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

A process is an instance of a program running in Linux.

In the Linux system, the operating system completes tasks one by one through processes, and the process is the basic unit for managing transactions. The process has its own independent processing environment (such as: which environment variables are currently needed, where is the directory where the program is running, which user is currently running the program, etc.) and system resources (such as: processor CPU occupancy, memory, I /O devices, data, programs).

When you execute a program in a Linux system, the system will create a specific environment for the program. This environment contains everything the system needs to run the program.

Every time you execute a command in Linux, it creates, or starts, a new process. For example, when you try to run the command "ls -l" to list the contents of a directory, you start a process. If there are two terminal windows displayed on the screen, then you may have run the same terminal program twice, and there will be two terminal processes.

Each terminal window may be running a Shell, and each running Shell is a process. When you call a command from the Shell, the corresponding program will be executed in a new process. When the program's process execution is completed, the Shell's process will resume running.

The operating system tracks processes through a numerical code called a PID or process ID. Every process in the system has a unique PID.

Now we use an example to understand the process in Linux. We execute the following command on the Shell command line:

$ sleep 10 &
[1] 3324
Copy after login

Because the program will wait for 10 seconds, we quickly search for any process named sleep on the current Shell:

$ ps -ef | grep sleep
mozhiyan  3324  5712  cons1  17:11:46  /usr/bin/sleep
Copy after login

We see A process named /usr/bin/sleep is running on the system (its PID is the same as the PID we got in the previous command).

Now, we try to run the above sleep command from 3 different terminal windows in parallel. The output of the above command will be similar to the following:

$ ps -ef | grep sleep
mozhiyan  896   5712  cons1  17:16:51  /usr/bin/sleep
mozhiyan  5924  5712  cons1  17:16:52  /usr/bin/sleep
mozhiyan  2424  5712  cons1  17:16:50  /usr/bin/sleep
Copy after login

We see each of the sleep program Instances are created as a separate process.

Each Linux process has another ID number, the ID of the parent process (ppid). Every user process in the system has a parent process.

The command "ps -f" will list the PID and PPID of the process. The output of this command is similar to the following:

$ ps -f
   UID     PID   PPID    TTY       STIME      COMMAND
mozhiyan  4124   228    cons0    21:37:09   /usr/bin/ps
mozhiyan   228   1      cons0    21:32:23   /usr/bin/bash
Copy after login

The commands you run at the Shell command line prompt all use the current Shell process as the parent process. For example, if you enter the ls command at the Shell command line prompt, the Shell will execute the ls command. At this time, the Linux kernel will copy the Shell's memory page and then execute the ls command.

In Unix, each process is created using the fork and exec methods. However, this approach results in a loss of system resources.

In Linux, the fork method is implemented using copy-on-write memory pages, so it only causes the loss of time and memory required to copy the memory page table of the parent process, and will create a new page table for the child process. A unique task structure.

The copy-on-write mode avoids creating unnecessary structure copies when creating a new process. For example, if the user outputs the ls command at the Shell command line prompt, the Linux kernel will create a Shell child process, that is, the Shell process is the parent process, and the ls command process is the child process. The ls command process will point to this Shell uses the same memory page, and then the child process uses copy-on-write technology to execute the ls command.

State of the process

Each Linux process has its own life cycle, such as creation, execution, termination and cleanup. Each process also has its own status, which shows what is currently happening in the process. The status of a process changes, including process creation, scheduling, and death.

The process can have the following states:

  • D (uninterruptible sleep state) - the process is sleeping and cannot be resumed until an event occurs.

  • R (Running status) - The process is running.

  • S ​​(Sleep state) - The process is not running, but is waiting for an event or signal.

  • T (stop state) - The process is stopped by a signal, such as the signal SIGINT or SIGSTOP.

  • Z (Zombie state) - Processes marked are zombie processes and remain because their parent process properly destroyed them. If the parent process exits, these processes will be destroyed by the init process.

To view the status of the specified process, you can use the following command:

ps -C processName -o pid=,cmd,stat
Copy after login

For example:

$ ps -C sleep -o pid=,cmd,stat
      CMD       STAT
9434 sleep 20    S
Copy after login

Related recommendations: "Linux Video Tutorial

The above is the detailed content of What does process mean in linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template