Use commands to convert foreground and background processes to each other

1. Shell supports role control, with the following commands:

command to let the process run in the background

jobs -l View processes running in the background

fg %n brings the process n running in the background to the foreground

bg %n let process n go to the background

PS: "n" is the Jincheng number viewed by jobs

 

2. Execute the command & switch to the background

   When running a command in the Linux terminal, put the ampersand at the end of the command to make the program run in the background.

 

3. Switch running programs to the background

   If the program is running in the foreground, you can use Ctrl+z to pause the program first, and then use the bg %[number] command to run the program in the background. This step is divided into three steps:

 1. Pause the program to run Ctrl+z

 Ctrl+z is related to system tasks. Ctrl+z can put a command that is being executed in the foreground to the background. and pause.

 [Oracle@linuxidc ~]$ sh ins.sh 
  [1]+Stopped ins.sh
2. View the suspended program to
view the jobs Use the jobs or ps command to view the running jobs. .
[oracle@linuxidc ~]$ jobs -l
  [1]+ 4524Stopped ins.sh
The result of executing the jobs command, + indicates a current job, and - indicates a job after the current job. 
The jobs -l option displays the PIDs of all tasks, and the status of jobs can be running or stopped. Terminated
3. The background bg of the switching program
will turn a suspended command in the background into multiple commands in the background of the weak country. You can use bg %jobnumber to call out the selected command
[oracle@linuxidc ~]$ bg %1
  [oracle@linuxidc ~]$ jobs -l
  [1]+ 4524Running ins.sh
  4. Switch the program to the foreground
  You can also use the fg %[number] command to drop a program to the foreground to run
  [oracle@linuxidc ~]$ fg %1
  . /tcpserv01
  5. Terminate background programs
  It is also possible to directly terminate programs running in the background, use the kill command
  [oracle@linuxidc ~] $ kill %1
  But if the task is terminated (kill), the shell is from the list known to the current shell environment Deletes the process ID of the task; that is, the jobs command displays information about tasks that are running or suspended in the background in the current shell environment.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324947618&siteId=291194637