Pre-and-post switching commands and methods for Linux processes

Source: Internet
Author: User
Tags rsync

In the process of managing a server, often when editing this file, suddenly to see other information, this is the time, the usual way is to exit the edit, and then to view the information.

But if we combine FG with BG command, we can make our work more efficient.

The commands involved in inter-process switching are as follows:

CTRL + C
Terminate and exit the execution of the foreground command and return to the shell
Ctrl+z
Pause the execution of the foreground command, put the process into the background, and return to the shell
Jobs
View the commands that are currently executing in the background to view the command process number
&
When you run the command, add & at the end of the command to allow the command to execute in the background
FG N
The command process with the command process number N is placed in the foreground, with the%n
BG N
Put the command process number n in the background execution
Through Crtl+z can put the current information into the background to execute, want to call, execution FG n can be invoked, and this n query can be achieved through jobs.

Like what:
[Root@liufofu ~]# Jobs
[1] Running/usr/local/mysql5.5.38/bin/mysqld_safe–user=mysql & (wd:/usr/local/mysql5.5.38)
[2]-Stopped Vim x.py
[3]+ Stopped Vim x.sh

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
If you do not have this prompt, view the task with the jobs command:
#jobs
[1]+ suspended/root/bin/rsync.sh &
Then we can schedule the program to run in the background: (the number for the BG is the job number)
#bg 1
[1]+/root/bin/rsync.sh &
To view a running task with the jobs command:
#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
That way, you can only wait for the task to complete on the console.

At the time of the call, you can use FG 2 to invoke the x.py that you just edited to continue working.

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.