How to make commands run in the background in Linux

Source: Internet
Author: User
Tags autoload

1. Add &amp to the command after the order, and you can make the command work in the background, the greatest benefit is not afraid to be interrupted by the CTRL + C interrupt instruction. 2. Then you may ask again, how does the program in the background make it back to the foreground? It's simple, just use the FG command, and you can do it. 3. Some students may ask again, I have now run the command in the foreground, I can put it in the background to run it? Of course, as long as the implementation of CTRL + Z can be done. is not great Ah! 4. Speaking of some students may ask again, if I have more than one process in the background to run, then how to restore to the foreground to execute it? This is the time to use the jobs command, through the jobs command, to list all the processes executed in the background, the number in brackets ([]) is the name of jobs, and through FG%number can restore the specified background process. Use Nohup to let the program run in the remote host background because I purchased a foreign host actually opened the Telnet permissions, so I also use Telnet login to play Linux, but found that a closed window automatically and the host disconnected, and Windows terminal is not the same, so just look for the internet And found a way to run a program from the background. Unix/linux generally like to let a program run in the background, many use & at the end of the program to let the program run automatically. For example we want to run MySQL in the background:/usr/local/mysql/bin/mysqld_safe–user=mysql & But many of our programs do not make daemons like mysqld, and maybe our program is just a normal program. Generally this program uses & end, but if the terminal is closed, then the program will be closed. But in order to be able to run in the background, then we can use the Nohup command, such as we have a test.php need to run in the background, and want to be able to run regularly in the background, then use nohup:nohup/root/test.php & Tip: [~]$ Appending output to nohup.out well, it proves that the operation was successful, and that the program running outputs were placed in the Nohup.out file of the current directory. Attached: nohup Command Reference nohup command purpose: To run the command without hanging off. Syntax: Nohup Command [Arg ...] [&]
Description: The nohup command runs commands specified by the command parameter and any related ARG parameters, ignoring the
There is a hang-off (SIGHUP) signal. Use the Nohup command to run a program in the background after logging off. To run [...] in the background
1. Two commands running in the background & and Ctr+z
At the beginning of the + "&" Specific method is: [Command] space [&]
Like what:
[[email protected] etc]# Find/-name XML &
This way, the Finder will run in the background. It runs without affecting you to do anything else.
But sometimes I forget to add "&amp" after the order, and I do not want to stop this command to rewrite it again. This is available
to press [Ctrl + Z], the current program into the background.
[[email protected] etc]# Find/-name XML
/etc/xml
/usr/lib64/python2.4/xml
/usr/share/vim/vim70/autoload/xml
/usr/share/hplip/data/xml
/usr/share/java-utils/xml
/usr/share/xml
/usr/share/doc/libvorbis-devel-1.1.2/xml
/usr/local/apache-tomcat-6.0.14/webapps/examples/jsp/xml
/webapp/web/jsp/xml
[[email protected] etc]# Find/-name XML
/etc/xml
/usr/lib64/python2.4/xml
/usr/share/vim/vim70/autoload/xml
/usr/share/hplip/data/xml
/usr/share/java-utils/xml
/usr/share/xml [1]+ Stopped Find/-name XML but note that at this point the program in the background is in the Stopped state (note the last line above). Use jobs to view the running program in the background. [[email protected] etc]# jobs [1]-Stopped Find/-name XML [2]+ Stopped vi/etc/hosts can be used with command BG 2. The effect is the same as in the beginning with the Find/-name xml&, so that the command runs in the background. 2. Back to the foreground according to the jobs show, with the use of FG 2 to the corresponding program to the front desk

How to make commands run in the background in Linux

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.