[Go] Linux skillfully use ctrl-z background run program

Source: Internet
Author: User
Tags rsync

Background:

Recently in the implementation of some long-time procedures, always accidentally forgot to enter the ' & ', the end of the terminal is stuck there, it is depressed

A new terminal was always opened in the past.

Today, look at "Bird Brother's Linux private dishes", when the introduction of vim introduced a ctrl-z command can be the current program cut into the background, very useful! But how do you cut it back? Search, see below:

-----------reprinted from: http://blog.chinaunix.net/uid-10219166-id-2968756.html

-----------The following is the original
Suppose you find that a program running in the foreground takes a long time, but you need to do something else, you can use CTRL-Z to terminate the program, and then you can see the system prompt:

[1]+ stopped/root/bin/rsync.sh

Then we can schedule the program to execute in the background: (the number behind BG is the job number)

#bg 1

[1]+/root/bin/rsync.sh &

Use the Jobs command to view the tasks that are running:

#jobs

[1]+ running/root/bin/rsync.sh &

If you want to bring it back to the foreground, you can use

#fg 1

/root/bin/rsync.sh

This way, you can only wait for the task to complete on the console.

& Throw instructions into the background to execute

[Ctrl]+z left the foreground task in the background to pause

Jobs view the working status of the background

FG%jobnumber The backstage task to the front desk for processing.

BG%jobnumber put tasks in the background to handle

Kill management tasks in the background

The command runs with CTRL + Z, forcing the current process to turn to the background and stop it.

1. Bring the process back to run (background)

(1) using the command BG

Example:

[email protected]: ~/unp/tcpcliserv$./tcpserv01

* CTRL + Z is used here, SERV01 is a stop state at this time *

[1]+ Stopped./tcpserv01

[email protected]: ~/unp/tcpcliserv$ BG

[1]+./TCPSERV01 & * At this time serv01 run in the background *

[email protected]: ~/unp/tcpcliserv$

(2) If you use CTRL + Z to stop a few programs?

Example:

[email protected]: ~/unp/tcpcliserv$ jobs

[1]-Running./TCPSERV01 &

[2]+ Stopped./tcpcli01 127.0.0.1

[email protected]: ~/unp/tcpcliserv$ BG%1

BASH:BG: Task 1 has been transferred to background * background run *

2. Restore the process to the foreground run

Example:

[email protected]: ~/unp/tcpcliserv$./tcpserv04

[1]+ Stopped./tcpserv04

[email protected]: ~/unp/tcpcliserv$ FG

。 /tcpserv04

Summary:

(1) Ctrl + Z Stop the process and put in the background

(2) Jobs shows the currently paused process

(3) BG%N enables the nth task to run in the background (with a space before%)

(4) FG%N to enable nth tasks to run in the foreground

The default BG,FG indicates the last process action without%n!

---------above is the original

PostScript: "Bird Brother's Linux private dishes" There are also chapters on FG and BG, but did not see

[Go] Linux skillfully use ctrl-z background run program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.