The nohup command is a very practical Linux command that can ignore the SIGHUP signal when running a program on the command line, so that the program can continue to run after the user logs out. In actual use, we often encounter situations where we need to run a program in the background and keep it running continuously. This article will introduce the basic usage of the nohup command and share some shutdown techniques after running the nohup command.
First, let us understand the basic usage of nohup command. The format of the nohup command is as follows:
nohup command [arg] &
Among them,command
is the command that needs to be run in the background, andarg
is the parameter of thecommand
command. You can make a command run in the background by adding&
at the end of the command. After executing this command, the terminal will output a prompt message informing the user that the log output by nohup will be recorded in thenohup.out
file in the current directory.
After using the nohup command, sometimes We will need to manually close the programs running in the background. First, we need to see the process ID (PID) of the program. You can view the PID of the program running in the background through the following command:
ps -ef | grep command_name
wherecommand_name
is the name of the program running in the background.
After obtaining the PID of the program, we can use thekill
command to close the program . The format of the kill command is as follows:
kill -15 PID
Among them, the-15
parameter represents the software stop signal. Send this signal to the program with the specified PID to close the program. If you want to forcefully close the program, you can use thekill -9 PID
command.
In addition to using PID to close the program, we can also use thepkill
command to close the program according to the process name to close the program. The format of the pkill command is as follows:
pkill -f command_name
Among them, the-f
parameter indicates the use of regular expressions to match process names, which can match multiple processes more flexibly.
If you want to view the tasks running in the background in the current system, you can use thejobs
command . Thejobs
command will list the tasks running in the background in the current terminal session, as well as the status of the tasks.
Through the above techniques, we can use the nohup command more flexibly and safely close programs running in the background to ensure safe and stable operation of the system.
This article introduces the basic usage of the nohup command and some shutdown techniques, hoping to help readers better understand and apply the nohup command. In actual use, you must operate with caution to avoid misoperation causing system instability or data loss. I hope this article is helpful to you, thank you for reading!
The above is the detailed content of Shutdown techniques after running the nohup command. For more information, please follow other related articles on the PHP Chinese website!