Nohup and & Combine jobs with easy-to-use operation notes!

Source: Internet
Author: User

[[email protected] ~]# nohup./ren.sh &-& on behalf of the background run

[1] 56833

[[email protected] ~]# nohup: Ignore input and append output to "Nohup.out"--enter enter jobs to view background program

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[[email protected] ~]# jobs-jobs view programs running in the background

[1]+ Running nohup./ren.sh &

[email protected] ~]# cat ren.sh

/bin/sleep 50s

[Email protected] ~]#

[[email protected] ~]# FG 1-recall the foreground run Crtl+z stop running

Nohup./ren.sh

[[email protected] ~]# jobs

[1]+ Stopped nohup./ren.sh

[[Email protected] ~]# PS aux |grep./ren

Root 56839 0.0 0.1 106056 1272 pts/1 T 09:23 0:00/bin/sh./ren.sh

Root 56843 0.0 0.0 103248 876 pts/1 s+ 09:25 0:00 grep./ren

[Email protected] ~]#

[Email protected] ~]# kill-9 56839

[[Email protected] ~]# PS aux |grep./ren

Root 56845 0.0 0.0 103248 876 pts/1 s+ 09:26 0:00 grep./ren

[1]+ has killed Nohup./ren.sh

[Email protected] ~]#

[[email protected] ~]# jobs-No background program Jobs-l view at this time

[Email protected] ~]#

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Email protected] ~]#./ren.sh &

[1] 56851

[Email protected] ~]#./1.sh &

[2] 56853

[[email protected] ~]# jobs

[1]-Running./ren.sh &-Represents the need to wait for the background 1 process to finish executing in 2

[2]+ Running./1.sh &

[email protected] ~]# cat ren.sh

/bin/sleep 50s

[email protected] ~]# cat 1.sh

/bin/sleep 50s

[Email protected] ~]#

[Email protected] ~]#./ren.sh &

[1] 56874

[Email protected] ~]#./1.sh &

[2] 56876

[[email protected] ~]# jobs

[1]-Running./ren.sh &

[2]+ Running./1.sh &

[[email protected] ~]# jobs

[1]-done./ren.sh

[2]+ Running./1.sh &

[[email protected] ~]# jobs

[2]+ Running./1.sh &

[[email protected] ~]# jobs

[2]+ Running./1.sh &

[[email protected] ~]# jobs

[2]+ done./1.sh

[[email protected] ~]# jobs

[Email protected] ~]#

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

BG will suspend a command in the background and turn it on!

[Email protected] ~]#./ren.sh

^z

[1]+ Stopped./ren.sh

[[email protected] ~]# BG 1

[1]+./ren.sh &

[[email protected] ~]# jobs

[1]+ Running./ren.sh &

[Email protected] ~]#

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

What is the difference between Nohup and &?

&: Put the task in the background, even if close Xshell exits the current session continues to run, but standard output and standard error messages are lost

Nohup: Put the task in the background, turn off standard input, the foreground is no longer able to receive any input (standard input), redirect standard output and standard error to the file Nohup.out in the current directory, even if close Xshell exits the current session continues to run.

Disadvantages of Nohup and &:

If you want to execute multiple commands and scripts in a shell session, it is very cumbersome to add nohup and & to each command and script, so tools such as screen and Tmux are made.


This article from "Ningzhiyuan @it share" blog, declined reprint!

Nohup and & combine jobs with easy-to-use action notes!

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.