The two different process startup methods in Linux are: 1. Manually starting the process, which refers to directly starting a process by the user inputting a command. According to the type and nature of the started process, it can be subdivided into There are two methods: foreground startup and background startup; 2. Scheduling the startup process means that the task can be configured to start automatically at a specified time, date, or when the average system load is lower than a specified value.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Generally speaking, there are two main ways to start a process, namely manual startup and scheduling startup (set in advance, according to According to user requirements, the process can be started by itself). Next, we will introduce these two methods one by one.
Linux manual startup process
Manual startup process refers to starting a process directly by the user inputting a command. According to the started Depending on the type and nature of the process, it can be subdivided into two methods: foreground startup and background startup.
Start the process in the foreground
This is the most common way to start the process manually, because when the user enters a command and runs it, a process has been started, and it is a For the process in the foreground, the system is actually in a multi-process state at this time (one is the Shell process and the other is a newly started process).
In fact, there are many processes quietly running in the background when the system is automatic, but for the convenience of readers' understanding, these processes are not included here.
If you start a time-consuming process, then suspend the process, and use the ps command to view it, you will see the process in the ps display list, for example:
[root@localhost ~]# find / -name demo.jpg <--在根目录下查找 demo.jpg 文件,比较耗时 #此处省略了该命令的部分输出信息 #按“CTRL+Z”组合键,即可将该进程挂起 [root@localhost ~]# ps <--查看正在运行的进程 PID TTY TIME CMD 2573 pts/0 00:00:00 bash 2587 pts/0 00:00:01 find 2588 pts/0 00:00:00 ps
Suspending a process means putting the process running in the foreground into the background and suspending its operation. The usage of suspended processes and the ps command will be introduced in detail in subsequent chapters.
Check the process information by running the ps command. You can see that the process number of the find command just executed is 2587, and the process number of the ps process is 2588.
Start the process in the background
The process runs directly from the background and is used relatively rarely, unless the process is very time-consuming and the user is not in a hurry to need its running results. When, for example, the user needs to start a long-running process for formatting text files, in order to prevent the entire Shell from being "occupied" during the formatting process, it is a wise choice to start the process from the background.
Starting a process from the background is actually adding an "&" symbol at the end of the command (note that there is a space before the &). After entering the command and running it, the Shell will provide us with a number, which is the process number of the process. Then the prompt will appear directly, and the user can continue to complete other tasks, such as:
[root@localhost ~]# find / -name install.log & [1] 1920 #[1]是工作号,1920是进程号
The above introduces two ways to start manually. In fact, they have a common feature, that is, new processes are started by The current Shell process is generated. In other words, Shell creates a new process, so this relationship is called the parent-child relationship between processes, where Shell is the parent process and the new process is the child process.
It is worth mentioning that a parent process can have multiple child processes, and usually the parent process can be continued only after the child process ends; of course, if it is started from the background, the parent process does not need to wait for the child process.
Linux Scheduling Startup Process
In Linux systems, tasks can be configured to occur at a specified time, date, or when the average system load is lower than Automatically starts when a value is specified.
For example, Linux is pre-configured to run important system tasks so that the system can be updated in real time. System administrators can also use automated tasks to regularly back up important data.
Recommended learning: Linux video tutorial
The above is the detailed content of What are the two different process startup methods in Linux?. For more information, please follow other related articles on the PHP Chinese website!