View and terminate running daemon methods in Linux

  • 2021-06-28 14:52:28
  • OfStack

linux Task Management - Background Run and Terminate

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

1. &

At the end of a command, you can put it in the background for execution, such as gftp & ,

2. ctrl + z

A command being executed in the foreground can be put in the background, paused, and not executable

3. jobs

See how many commands are currently running in the background

jobs

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

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

Deletes the process identity of the task from a list known to the current shell environment;That is, the jobs command displays information about tasks that are running or suspended in the background from the current shell environment.

4. fg

Move commands 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 (not pid) which was found by the jobs command.

5. bg

Change a command suspended in the background to continue execution (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 (not pid) which was found by the jobs command.

Move tasks to background:

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

Concept: Current Task

If there are two task numbers in the background, [1], [2];If the first background task is successfully completed and the second background task is still in progress, the current task will automatically become the background task number'[2]'

Background tasks.So here's one point, that is, the current task will change.When a user enters commands such as "fg", "bg" and "stop", the current task changes without any quotation marks

Termination of process

Termination of background processes:

Method 1:

View job number (assuming num) through the jobs command and execute kill%num

Method 2:

View the process number of job (PID, assuming pid) through the ps command, then execute kill pid

Termination of foreground process:

ctrl+c

Other roles of kill

In addition to terminating the process, kill can also send other signals to the process. kill-l allows you to see the signals supported by kill.

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

Process Suspend

Suspend background processes:

Execute in solaris by stop command, view job number (assuming num) by jobs command, and execute stop%num;

In redhat, there is no stop command, and the process can be suspended by executing the command kill - stop PID;

When the currently suspended task is to be re-executed, the status of the suspended job can be changed from stopped to running through bg%num, which is still executing in the background;When you need to execute in the foreground instead, execute the command fg%num;

Pending foreground process:

ctrl+Z;


Related articles: