How to view and terminate running background programs in Linux

How to view and terminate running background programs in Linux

Linux task management - background running and termination

fg, bg, jobs, &, ctrl + z commands

one, &

Adding it to the end of a command can put the command into the background for execution, such as gftp &,

2. ctrl + z

You can put a command that is being executed in the foreground into the background and put it in a paused state, making it unexecutable.

Jobs

Check how many commands are currently running in the background

jobs

The -l option displays the PID of all jobs. The status of jobs can be running, stopped,

Terminated, but if the task is terminated (kill), the shell

Delete the process ID of the task from the list known to the current shell environment; that is, the jobs command displays the information of the background running or suspended tasks in the current shell environment;

4. fg

Bring the command in the background to the foreground to continue running

If there are multiple commands in the background, you can use fg %jobnumber to call out the selected command. %jobnumber is the serial number of the command being executed in the background found by the jobs command (not pid)

5. bg

Turn a command that was paused in the background into one that continues to execute (execute in the background)

If there are multiple commands in the background, you can use bg %jobnumber to call out the selected command. %jobnumber is the serial number of the command being executed in the background found by the jobs command (not pid).

Move the task to the background:

First press ctrl + z; then bg, so that the process is moved to the background and the terminal can continue to accept commands.

Concept: Current Tasks

If there are two background task numbers, [1] and [2]; if the first background task is successfully completed and the second background task is still being executed, the current task will automatically become the background task number "[2]"

Background tasks. So we can conclude that the current tasks will change. When the user enters commands such as "fg", "bg" and "stop" without any quotation marks, the current task will be changed.

Termination of a process

Termination of background processes:

Method 1:

Use the jobs command to check the job number (assuming it is num), and then execute kill %num

Method 2:

Use the ps command to view the process ID (PID, assuming it is pid) of the job, and then execute kill pid

Termination of the foreground process:

ctrl+c

Other functions of kill

In addition to terminating a process, kill can also send other signals to the process. Use kill -l to view the signals supported by kill.

SIGTERM is the signal sent by kill without parameters, which means that the process should be terminated, but whether it is executed or not depends on whether the process supports it. If the process has not terminated, you can use kill -SIGKILL pid. This is done by the kernel to terminate the process, and the process cannot listen to this signal.

Process Suspension

Background process hangs:

In Solaris, use the stop command to execute, use the jobs command to check the job number (assuming it is num), and then execute stop %num;

In redhat, there is no stop command. You can suspend the process by executing the kill -stop PID command.

When you want to re-execute the currently suspended task, you can use bg %num to change the status of the suspended job from stopped to running, and it will still be executed in the background. When you need to change it to foreground execution, execute the command fg %num.

Suspension of foreground process:

ctrl+Z;

The above method of viewing and terminating running background programs in Linux is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to install Redis in Linux, run it in the background, and set up the system to start automatically
  • Several ways of running in the background of Linux (summary)
  • How to view and close background running programs in Linux
  • Linux nohup to run programs in the background and view them (nohup and &)
  • How to start jar package and run it in the background in Linux
  • A brief analysis of the examples and differences of using nohup and screen to run background tasks in Linux
  • Several ways to run Python programs in the Linux background
  • How to run springboot in the background of linux
  • Linux background running node service command method
  • Solve the problem of python nohup linux background running output
  • Summary of methods for reliably running processes in the background in Linux
  • Detailed explanation of Linux background operation and shutdown, view background tasks
  • How to run Linux commands in the background

<<:  How to access MySql through IP address

>>:  Comparative Analysis of IN and Exists in MySQL Statements

Blog    

Recommend

How to draw the timeline with vue+canvas

This article example shares the specific code of ...

Detailed explanation of Vue life cycle functions

Table of contents Lifecycle Functions Common life...

Detailed explanation of MySQL master-slave replication and read-write separation

Table of contents Preface 1. Overview 2. Read-wri...

Docker Getting Started Installation Tutorial (Beginner Edition)

Doccer Introduction: Docker is a container-relate...

Design Theory: Hierarchy in Design

<br />Original text: http://andymao.com/andy...

js learning notes: class, super and extends keywords

Table of contents Preface 1. Create objects befor...

How to use http and WebSocket in CocosCreator

Table of contents 1. HttpGET 2. HTTP POST WebSock...

Detailed explanation of VUE Token's invalidation process

Table of contents Target Thought Analysis Code la...

Basic syntax of MySQL index

An index is a sorted data structure! The fields t...

Solution to "Specialized key was too long" in MySQL

Table of contents Solution 1 Solution 2 When crea...

Install Zookeeper under Docker (standalone and cluster)

After starting Docker, let's take a look at t...

Docker installs and runs the rabbitmq example code

Pull the image: [mall@VM_0_7_centos ~]$ sudo dock...

Solution to Vue's inability to watch array changes

Table of contents 1. Vue listener array 2. Situat...