Home  >  Article  >  Operation and Maintenance  >  How to use the linux nohup command to enable the program to continue running in the background after exiting the terminal

How to use the linux nohup command to enable the program to continue running in the background after exiting the terminal

王林
王林forward
2023-05-26 09:48:092594browse

Under Unix/Linux, you generally want a program to run in the background. Many people use & at the end of the program to make the program run automatically; but if you want the program to still run in the background after exiting the terminal, you need to use This is achieved by combining nohup with &.

nohup command

Purpose: Run the command without hanging up

Syntax: nohup Command [ Arg … ] [& ]

##Description The nohup command runs the command specified by the Command parameter and any associated Arg parameters, ignoring all hangups ( SIGHUP) signal. Use the nohup command to run a program in the background after logging out: To run a nohup command in the background, add & to the end of the command.

Logging Whether or not the output of the nohup command is redirected to the terminal, the output will be appended to the nohup.out file in the current directory. If the nohup.out file in the current directory is not writable, output is redirected to the $HOME/nohup.out file. If no file can be created or opened for appending, the command specified by the Command parameter is not invoked.

Note when using After the nohup is successful in the shell, you still need to press any key on the keyboard on the terminal to return to the shell input command window, and then enter exit in the shell to exit the terminal; if you directly click the Close Program button to close the terminal after successfully executing nohup, the session corresponding to the command will be disconnected at this time, causing the process corresponding to nohup to be notified that it needs to be shut down together, and it will not be called after closing the terminal. The program continues to run in the background.

Example:

$nohup python manage.py runserver &

The above is the detailed content of How to use the linux nohup command to enable the program to continue running in the background after exiting the terminal. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete