Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view and close background running programs by Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shares information about how Linux can view and disable background programs. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Linux is a free-to-use and freely distributed UNIX-like operating system, is a POSIX-based multi-user, multitasking, multi-threaded and multi-CPU operating system, using Linux to run major Unix tools, applications and network protocols.

1. Run the.sh file

Direct use of.../ sh file will work, but if you want to run it in the background, even if the current terminal is turned off, you need the nohup command and the & command.

(1)& Order

Function: added to the end of a command, you can put this command in the background execution

(2) The nohup command

Function: Run command without hanging up

2. View the current background running commands

There are two commands you can use, jobs and ps, the difference is that jobs is used to view the tasks running in the background of the current terminal, and you can't see them if you change the terminal. The ps command is used to view the dynamics of instantaneous processes, and you can see background processes running on other terminals.

1) The jobs order

Function: View tasks running in the background of the current terminal

The jobs -l option displays the PID of all tasks in the current terminal. The status of jobs can be running, stopped, Terminated.+ The sign indicates the current task, and the-indicates the next task.

(2) PS command

Function: View all current processes

ps -aux |grep "test.sh" #a: show all programs u: show all programs in user-oriented format x: show all programs, not differentiated by terminal

3. Close the current background running command

kill command: End the process

(1) Check jobnum with jobs command, then execute kill %jobnum

(2) Check the PID number by ps command, and then execute kill %PID.

If it is a foreground process, then simply execute Ctrl+c to terminate it.

4. Switching and control of front and background processes

(1) fg command

Function: adjust the command in the background to the foreground to continue running

If there are multiple commands in the background, you can first use jobs to view jobnun, and then use fg %jobnum to call up the selected command.

2) Ctrl + Z command

Function: Put a command that is being executed in the foreground into the background and is in a suspended state

(3) BG Order

Function: Change a command suspended in the background to continue execution in the background

If there are multiple commands in the background, you can first use jobs to view jobnum, and then use bg %jobnum to call up the selected command to continue execution.

Thank you for reading! About "Linux how to view and close the background running program method" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report