Get the App
SLTechnology News&Howtos  ›  Development  › 

How to view background processes by Linux

Shulou Source: shulou.com Published: 2022-06-01 20:03:07 10月31日 Update

This article is about how Linux looks at background processes. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The LINUX background process, also known as the daemon (Daemon), is a special process running in the background. It is independent of the control terminal and periodically performs certain tasks or waits for certain events to be processed.

1. Run the .sh file

You can run it directly with the. / sh file, but if you want to run in the background, you need the nohup command and the & command even if you close the current terminal.

(1) & Command

Function: add to the end of a command, you can put this command in the background to execute

(2) nohup command

Function: run commands without hanging up

2. View the commands currently running in the background

There are two commands available, jobs and ps, the difference is that jobs is used to view the tasks running in the background of the current terminal, which cannot be seen by changing the terminal. On the other hand, the ps command is used to view the dynamics of the instant process, and you can see the background processes running by other terminals.

(1) jobs command

Function: view the tasks currently running in the background of the terminal

The jobs-l option shows that the status of the PID,jobs for all tasks on the current terminal can be running,stopped,Terminated. The + sign indicates the current task, and the-sign indicates the latter task.

(2) ps command

Function: view all current processes

Ps-aux | grep "test.sh" # a: display all programs u: display all programs in a user-based format x: display all programs, not by terminal

3. Close the commands currently running in the background

Kill command: ending process

(1) View jobnum through the jobs command, and then execute kill% jobnum

(2) check the process number PID through the ps command, and then execute kill% PID

If it is a foreground process, you can terminate it by executing Ctrl+c directly.

4. Switching and control of front and background processes.

(1) fg command

Function: transfer the commands in the background to the foreground to continue to run

If you have more than one command in the background, you can first view the jobnun with jobs, and then call up the selected command with fg% jobnum.

(2) Ctrl + z command

Function: put a command being executed in the foreground in the background and be in a paused state

(3) bg command

Function: change a command that is paused in the background to continue execution in the background

If you have more than one command in the background, you can first view the jobnum with jobs, and then call up the selected command with bg% jobnum to continue execution.

Thank you for reading! This is the end of this article on "how to view background processes in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Command background process run terminal function task foreground content multiple file more status program article first use control good practical special Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Xiaomi Shulou Tech Info Linux Apple